class BatchController

Same name in other branches
  1. 9 core/modules/system/src/Controller/BatchController.php \Drupal\system\Controller\BatchController
  2. 8.9.x core/modules/system/src/Controller/BatchController.php \Drupal\system\Controller\BatchController
  3. 11.x core/modules/system/src/Controller/BatchController.php \Drupal\system\Controller\BatchController

Controller routines for batch routes.

Hierarchy

Expanded class hierarchy of BatchController

1 file declares its use of BatchController
BatchControllerTest.php in core/modules/system/tests/src/Unit/Batch/BatchControllerTest.php

File

core/modules/system/src/Controller/BatchController.php, line 16

Namespace

Drupal\system\Controller
View source
class BatchController implements ContainerInjectionInterface {
    use StringTranslationTrait;
    
    /**
     * Constructs a new BatchController.
     */
    public function __construct(string $root, BatchStorageInterface $batchStorage) {
        require_once $this->root . '/core/includes/batch.inc';
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->getParameter('app.root'), $container->get('batch.storage'));
    }
    
    /**
     * Returns a system batch page.
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     *   The current request object.
     *
     * @return \Symfony\Component\HttpFoundation\Response|array
     *   A \Symfony\Component\HttpFoundation\Response object or render array.
     *
     * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
     */
    public function batchPage(Request $request) {
        $output = _batch_page($request);
        if ($output === FALSE) {
            throw new AccessDeniedHttpException();
        }
        elseif ($output instanceof Response) {
            return $output;
        }
        elseif (isset($output)) {
            $title = $output['#title'] ?? NULL;
            $page = [
                '#type' => 'page',
                '#title' => $title,
                '#show_messages' => FALSE,
                'content' => $output,
            ];
            // Also inject title as a page header (if available).
            if ($title) {
                $page['header'] = [
                    '#type' => 'page_title',
                    '#title' => $title,
                ];
            }
            return $page;
        }
    }
    
    /**
     * The _title_callback for the system.batch_page.html route.
     *
     * @return string
     *   The page title.
     */
    public function batchPageTitle(Request $request) {
        $batch =& batch_get();
        if (!($request_id = $request->query
            ->get('id'))) {
            return '';
        }
        // Retrieve the current state of the batch.
        if (!$batch) {
            $batch = $this->batchStorage
                ->load($request_id);
        }
        if (!$batch) {
            return '';
        }
        $current_set = _batch_current_set();
        return !empty($current_set['title']) ? $current_set['title'] : '';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
BatchController::batchPage public function Returns a system batch page.
BatchController::batchPageTitle public function The _title_callback for the system.batch_page.html route.
BatchController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
BatchController::__construct public function Constructs a new BatchController.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.