_batch_page

_batch_page(Request $request)

Renders the batch processing page based on the current state of the batch.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request object.

See also

_batch_shutdown()

File

core/includes/batch.inc, line 34
Batch processing API for processes to run in multiple HTTP requests.

Code

function _batch_page(Request $request) {
  $batch = &batch_get();

  if (!($request_id = $request->query->get('id'))) {
    return FALSE;
  }

  // Retrieve the current state of the batch.
  if (!$batch) {
    $batch = \Drupal::service('batch.storage')->load($request_id);
    if (!$batch) {
      drupal_set_message(t('No active batch.'), 'error');
      return new RedirectResponse(\Drupal::url('<front>', [], ['absolute' => TRUE]));
    }
  }

  // Register database update for the end of processing.
  drupal_register_shutdown_function('_batch_shutdown');

  $build = array();

  // Add batch-specific libraries.
  foreach ($batch['sets'] as $batch_set) {
    if (isset($batch_set['library'])) {
      foreach ($batch_set['library'] as $library) {
        $build['#attached']['library'][] = $library;
      }
    }
  }

  $op = $request->query->get('op', '');
  switch ($op) {
    case 'start':
    case 'do_nojs':
      // Display the full progress page on startup and on each additional
      // non-JavaScript iteration.
      $current_set = _batch_current_set();
      $build['#title'] = $current_set['title'];
      $build['content'] = _batch_progress_page();
      break;

    case 'do':
      // JavaScript-based progress page callback.
      return _batch_do();

    case 'finished':
      // _batch_finished() returns a RedirectResponse.
      return _batch_finished();
  }

  return $build;
}
doc_Drupal
2016-10-29 09:57:05
Comments
Leave a Comment

Please login to continue.