You are here

public static function EntityReferenceActionsHandler::batchFinish in Entity reference actions 1.x

The batch finish callback.

Throws

\Drupal\Core\Form\EnforcedResponseException

File

src/EntityReferenceActionsHandler.php, line 335

Class

EntityReferenceActionsHandler
Provides the form functions to call actions on referenced entities.

Namespace

Drupal\entity_reference_actions

Code

public static function batchFinish() {
  $batch =& batch_get();

  // Copied form _batch_finished().
  \Drupal::service('batch.storage')
    ->delete($batch['id']);
  foreach ($batch['sets'] as $batch_set) {
    if ($queue = _batch_queue($batch_set)) {
      $queue
        ->deleteQueue();
    }
  }

  // Clean-up the session. Not needed for CLI updates.
  if (isset($_SESSION)) {
    unset($_SESSION['batches'][$batch['id']]);
    if (empty($_SESSION['batches'])) {
      unset($_SESSION['batches']);
    }
  }
  $response = new AjaxResponse();
  $response
    ->addCommand(new CloseModalDialogCommand());
  $response
    ->addCommand(new MessageCommand(t('%action was successfully applied.', [
    '%action' => $batch['sets'][0]['title'],
  ]), '[data-entity-reference-actions-messages]'));

  // _batch_finished() only accepts a RedirectResponse. There is no
  // other chance to return our AjaxResponse without throwing this exception.
  throw new EnforcedResponseException($response);
}