You are here

public function RequestTranslationTmgmtActionApproveForm::submitForm in TMGMT Extension Suite 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/RequestTranslationTmgmtActionApproveForm.php \Drupal\tmgmt_extension_suit\Form\RequestTranslationTmgmtActionApproveForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides BaseTmgmtActionApproveForm::submitForm

File

src/Form/RequestTranslationTmgmtActionApproveForm.php, line 121

Class

RequestTranslationTmgmtActionApproveForm
Provides a confirmation form for sending multiple content entities.

Namespace

Drupal\tmgmt_extension_suit\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Retrieve selected jobs.
  $jobs = $this
    ->getEntities($this->entityIds);

  // Mark jobs as unprocessed for further processing.
  foreach ($jobs as $job) {

    // Requesting translation is possible only for unprocessed jobs.
    // See JobCheckoutManager::checkoutMultiple() method.
    $job
      ->setState(Job::STATE_UNPROCESSED);
    foreach ($job
      ->getItems() as $item) {

      // Reset statistics for the job item in order to have "count_pending"
      // value not equal to "0". See Job::requestTranslation() and
      // Job::getItems() methods.
      $item
        ->setState(JobItem::STATE_ACTIVE);
      $item
        ->resetData();
      $item
        ->recalculateStatistics();
      $item
        ->save();
    }
  }

  // Launch TMGMT's checkout process.
  $this->checkoutManager
    ->checkoutAndRedirect($form_state, $jobs);
  $this->jobQueue
    ->setDestination('/admin/tmgmt/jobs');
}