You are here

public static function CancelTmgmtActionApproveForm::processBatch in TMGMT Extension Suite 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/CancelTmgmtActionApproveForm.php \Drupal\tmgmt_extension_suit\Form\CancelTmgmtActionApproveForm::processBatch()
  2. 8 src/Form/CancelTmgmtActionApproveForm.php \Drupal\tmgmt_extension_suit\Form\CancelTmgmtActionApproveForm::processBatch()

Processes the sending batch.

Parameters

array $data: Keyed array of data to send.

array $context: The batch context.

Return value

JobInterface|mixed

Overrides BaseTmgmtActionApproveForm::processBatch

File

src/Form/CancelTmgmtActionApproveForm.php, line 51

Class

CancelTmgmtActionApproveForm
Provides a confirmation form for sending multiple content entities.

Namespace

Drupal\tmgmt_extension_suit\Form

Code

public static function processBatch($data, &$context) {
  $job = parent::processBatch($data, $context);
  if (!empty($job) && !$job
    ->abortTranslation()) {
    $context['results']['count']++;

    // This is the case when a translator does not support the abort
    // operation.
    // It would make more sense to not display the button for the action,
    // however we do not know if the translator is able to abort a job until
    // we trigger the action.
    foreach ($job
      ->getMessagesSince() as $message) {

      /** @var \Drupal\tmgmt\MessageInterface $message */
      if ($message
        ->getType() == 'debug') {
        continue;
      }
      if ($text = $message
        ->getMessage()) {

        // We want to persist also the type therefore we will set the
        // messages directly and not return them.
        drupal_set_message($text, $message
          ->getType());
      }
    }
  }
  else {
    $context['results']['errors'][] = new FormattableMarkup('Error aborting %name', [
      '%name' => $job
        ->label(),
    ]);
    return;
  }
  $context['message'] = new FormattableMarkup('Processed %name.', [
    '%name' => $job
      ->label(),
  ]);
}