3 namespace Drupal\system\Theme;
5 use Drupal\Core\Batch\BatchStorageInterface;
6 use Drupal\Core\Routing\RouteMatchInterface;
7 use Drupal\Core\Theme\ThemeNegotiatorInterface;
8 use Symfony\Component\HttpFoundation\RequestStack;
11 * Sets the active theme for the batch page.
13 class BatchNegotiator implements ThemeNegotiatorInterface {
18 * @var \Drupal\Core\Batch\BatchStorageInterface
20 protected $batchStorage;
25 * @var \Symfony\Component\HttpFoundation\RequestStack
27 protected $requestStack;
30 * Constructs a BatchNegotiator.
32 * @param \Drupal\Core\Batch\BatchStorageInterface $batch_storage
34 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
35 * The request stack used to retrieve the current request.
37 public function __construct(BatchStorageInterface $batch_storage, RequestStack $request_stack) {
38 $this->batchStorage = $batch_storage;
39 $this->requestStack = $request_stack;
45 public function applies(RouteMatchInterface $route_match) {
46 return $route_match->getRouteName() == 'system.batch_page';
52 public function determineActiveTheme(RouteMatchInterface $route_match) {
53 // Retrieve the current state of the batch.
54 $request = $this->requestStack->getCurrentRequest();
55 $batch = &batch_get();
56 if (!$batch && $request->request->has('id')) {
57 $batch = $this->batchStorage->load($request->request->get('id'));
59 // Use the same theme as the page that started the batch.
60 if (!empty($batch['theme'])) {
61 return $batch['theme'];