comparison core/modules/system/src/Theme/BatchNegotiator.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\system\Theme;
4
5 use Drupal\Core\Batch\BatchStorageInterface;
6 use Drupal\Core\Routing\RouteMatchInterface;
7 use Drupal\Core\Theme\ThemeNegotiatorInterface;
8 use Symfony\Component\HttpFoundation\RequestStack;
9
10 /**
11 * Sets the active theme for the batch page.
12 */
13 class BatchNegotiator implements ThemeNegotiatorInterface {
14
15 /**
16 * The batch storage.
17 *
18 * @var \Drupal\Core\Batch\BatchStorageInterface
19 */
20 protected $batchStorage;
21
22 /**
23 * The request stack.
24 *
25 * @var \Symfony\Component\HttpFoundation\RequestStack
26 */
27 protected $requestStack;
28
29 /**
30 * Constructs a BatchNegotiator.
31 *
32 * @param \Drupal\Core\Batch\BatchStorageInterface $batch_storage
33 * The batch storage.
34 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
35 * The request stack used to retrieve the current request.
36 */
37 public function __construct(BatchStorageInterface $batch_storage, RequestStack $request_stack) {
38 $this->batchStorage = $batch_storage;
39 $this->requestStack = $request_stack;
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function applies(RouteMatchInterface $route_match) {
46 return $route_match->getRouteName() == 'system.batch_page';
47 }
48
49 /**
50 * {@inheritdoc}
51 */
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'));
58 }
59 // Use the same theme as the page that started the batch.
60 if (!empty($batch['theme'])) {
61 return $batch['theme'];
62 }
63 }
64
65 }