class BatchNegotiator

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

Sets the active theme for the batch page.

Hierarchy

  • class \Drupal\system\Theme\BatchNegotiator implements \Drupal\Core\Theme\ThemeNegotiatorInterface

Expanded class hierarchy of BatchNegotiator

1 string reference to 'BatchNegotiator'
system.services.yml in core/modules/system/system.services.yml
core/modules/system/system.services.yml
1 service uses BatchNegotiator
theme.negotiator.system.batch in core/modules/system/system.services.yml
Drupal\system\Theme\BatchNegotiator

File

core/modules/system/src/Theme/BatchNegotiator.php, line 13

Namespace

Drupal\system\Theme
View source
class BatchNegotiator implements ThemeNegotiatorInterface {
    
    /**
     * The batch storage.
     *
     * @var \Drupal\Core\Batch\BatchStorageInterface
     */
    protected $batchStorage;
    
    /**
     * The request stack.
     *
     * @var \Symfony\Component\HttpFoundation\RequestStack
     */
    protected $requestStack;
    
    /**
     * Constructs a BatchNegotiator.
     *
     * @param \Drupal\Core\Batch\BatchStorageInterface $batch_storage
     *   The batch storage.
     * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
     *   The request stack used to retrieve the current request.
     */
    public function __construct(BatchStorageInterface $batch_storage, RequestStack $request_stack) {
        $this->batchStorage = $batch_storage;
        $this->requestStack = $request_stack;
    }
    
    /**
     * {@inheritdoc}
     */
    public function applies(RouteMatchInterface $route_match) {
        return $route_match->getRouteName() == 'system.batch_page.html';
    }
    
    /**
     * {@inheritdoc}
     */
    public function determineActiveTheme(RouteMatchInterface $route_match) {
        // Retrieve the current state of the batch.
        $request = $this->requestStack
            ->getCurrentRequest();
        $batch =& batch_get();
        if (!$batch && $request->request
            ->has('id')) {
            $batch = $this->batchStorage
                ->load($request->request
                ->get('id'));
        }
        // Use the same theme as the page that started the batch.
        if (!empty($batch['theme'])) {
            return $batch['theme'];
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
BatchNegotiator::$batchStorage protected property The batch storage.
BatchNegotiator::$requestStack protected property The request stack.
BatchNegotiator::applies public function
BatchNegotiator::determineActiveTheme public function
BatchNegotiator::__construct public function Constructs a BatchNegotiator.

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