You are here

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

Process batch method.

Parameters

$data:

$context:

File

src/Form/RequestTranslationApproveForm.php, line 348

Class

RequestTranslationApproveForm

Namespace

Drupal\tmgmt_extension_suit\Form

Code

public static function processBatch($data, &$context) {
  $message = 'Requesting translations...';
  $source_language = 'en';
  switch ($data['plugin']) {
    case 'content':
      $entity_manager = Drupal::entityTypeManager();
      $entity = $entity_manager
        ->getStorage($data['item_type'])
        ->load($data['item']);
      $source_language = $entity
        ->language()
        ->getId();
      break;
    case 'config':
      $config_factory = Drupal::configFactory()
        ->get($data['item']);
      $source_language = $config_factory
        ->get('langcode');
      break;
  }
  $job = tmgmt_job_create($source_language, $data['target_language'], Drupal::currentUser()
    ->id(), [
    'settings' => $data['settings'],
  ]);
  $job
    ->addItem($data['plugin'], $data['item_type'], $data['item']);
  $job->translator = $data['translator'];
  $job
    ->setState(JobInterface::STATE_ACTIVE);
  Drupal::service('tmgmt_extension_suit.utils.queue_unique_item')
    ->addItem('tmgmt_extension_suit_upload', [
    'id' => (int) $job
      ->id(),
  ]);
  $translator_plugin = $job
    ->getTranslatorPlugin();
  if ($translator_plugin instanceof ExtendedTranslatorPluginInterface) {
    Drupal::getContainer()
      ->get('logger.channel.tmgmt_extension_suit')
      ->info(t('File upload queued (request translation in a batch). Job id: @job_id, file name: @name.', [
      '@name' => $translator_plugin
        ->getFileName($job),
      '@job_id' => $job
        ->id(),
    ]));
  }
  $context['message'] = $message;
  $context['results'][] = $job
    ->id();
}