You are here

public static function UploadTmgmtActionApproveForm::processBatch in TMGMT Extension Suite 8

Processes the sending batch.

Parameters

array $data: Keyed array of data to send.

array $context: The batch context.

Overrides BaseTmgmtActionApproveForm::processBatch

File

src/Form/UploadTmgmtActionApproveForm.php, line 36

Class

UploadTmgmtActionApproveForm
Provides a confirmation form for sending multiple content entities.

Namespace

Drupal\tmgmt_extension_suit\Form

Code

public static function processBatch($data, &$context) {
  if (!isset($context['results']['errors'])) {
    $context['results']['errors'] = [];
    $context['results']['count'] = 0;
  }
  $entity_type_id = $data['entity_type'];
  $entity_id = $data['entity_id'];
  $job = \Drupal::entityTypeManager()
    ->getStorage($entity_type_id)
    ->loadMultiple([
    $entity_id,
  ]);
  $job = reset($job);
  if (!$job) {
    $context['results']['errors'][] = t('Entity @entity_type:@entity_id not found', [
      '@entity_type' => $entity_type_id,
      '@entity_id' => $entity_id,
    ]);
  }
  elseif ($translator = $job
    ->getTranslator()) {
    $translator_plugin = $job
      ->getTranslatorPlugin();
    if ($translator_plugin instanceof ExtendedTranslatorPluginInterface) {
      \Drupal::getContainer()
        ->get('logger.channel.tmgmt_extension_suit')
        ->info(t('File upload triggered (view action). Job id: @job_id, file name: @name.', [
        '@name' => $translator_plugin
          ->getFileName($job),
        '@job_id' => $job
          ->id(),
      ]));
    }
    $translator
      ->getPlugin()
      ->requestTranslation($job);
    $context['results']['count']++;
    $context['message'] = new FormattableMarkup('Processed %name.', [
      '%name' => $job
        ->label(),
    ]);
  }
  else {
    $context['message'] = new FormattableMarkup('Skipped %name.', [
      '%name' => $entity_type_id,
    ]);
  }
}