You are here

public function DownloadByJobItemsTmgmtActionApproveForm::submitForm in TMGMT Translator Smartling 8.4

File

src/Form/DownloadByJobItemsTmgmtActionApproveForm.php, line 55

Class

DownloadByJobItemsTmgmtActionApproveForm
Provides a confirmation form for sending multiple content entities.

Namespace

Drupal\tmgmt_smartling\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $current_user_id = $this
    ->currentUser()
    ->id();
  $temp_storage_name = $this
    ->getTempStorageName();

  // Clear out the accounts from the temp store.
  $this->tempStoreFactory
    ->get($temp_storage_name)
    ->delete($current_user_id);
  if (!$form_state
    ->getValue('confirm')) {
    return;
  }
  $operations = [];
  foreach ($this->entityIds as $id => $entity_type) {
    $job = Job::load($id);
    if (empty($job)) {
      continue;
    }
    foreach ($job
      ->getItems() as $item) {
      $batch_item_data = [
        'tjid' => $job
          ->id(),
        'tjiid' => $item
          ->id(),
      ];
      $operations[] = [
        [
          get_class($this),
          'processBatch',
        ],
        [
          $batch_item_data,
        ],
      ];
    }
  }
  if (!empty($operations)) {
    $batch = [
      'title' => $this
        ->getConfirmText(),
      'operations' => $operations,
      'finished' => [
        get_class($this),
        'finishBatch',
      ],
    ];
    batch_set($batch);
  }
  else {
    $form_state
      ->setRedirect('system.admin_content');
  }
}