Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\user\Theme;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Config\ConfigFactoryInterface;
|
Chris@0
|
6 use Drupal\Core\Entity\EntityManagerInterface;
|
Chris@0
|
7 use Drupal\Core\Routing\AdminContext;
|
Chris@0
|
8 use Drupal\Core\Routing\RouteMatchInterface;
|
Chris@0
|
9 use Drupal\Core\Session\AccountInterface;
|
Chris@0
|
10 use Drupal\Core\Theme\ThemeNegotiatorInterface;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Sets the active theme on admin pages.
|
Chris@0
|
14 */
|
Chris@0
|
15 class AdminNegotiator implements ThemeNegotiatorInterface {
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * The current user.
|
Chris@0
|
19 *
|
Chris@0
|
20 * @var \Drupal\Core\Session\AccountInterface
|
Chris@0
|
21 */
|
Chris@0
|
22 protected $user;
|
Chris@0
|
23
|
Chris@0
|
24 /**
|
Chris@0
|
25 * The config factory.
|
Chris@0
|
26 *
|
Chris@0
|
27 * @var \Drupal\Core\Config\ConfigFactoryInterface
|
Chris@0
|
28 */
|
Chris@0
|
29 protected $configFactory;
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * The entity manager.
|
Chris@0
|
33 *
|
Chris@0
|
34 * @var \Drupal\Core\Entity\EntityManagerInterface
|
Chris@0
|
35 */
|
Chris@0
|
36 protected $entityManager;
|
Chris@0
|
37
|
Chris@0
|
38 /**
|
Chris@0
|
39 * The route admin context to determine whether a route is an admin one.
|
Chris@0
|
40 *
|
Chris@0
|
41 * @var \Drupal\Core\Routing\AdminContext
|
Chris@0
|
42 */
|
Chris@0
|
43 protected $adminContext;
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Creates a new AdminNegotiator instance.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @param \Drupal\Core\Session\AccountInterface $user
|
Chris@0
|
49 * The current user.
|
Chris@0
|
50 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
Chris@0
|
51 * The config factory.
|
Chris@0
|
52 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
Chris@0
|
53 * The entity manager.
|
Chris@0
|
54 * @param \Drupal\Core\Routing\AdminContext $admin_context
|
Chris@0
|
55 * The route admin context to determine whether the route is an admin one.
|
Chris@0
|
56 */
|
Chris@0
|
57 public function __construct(AccountInterface $user, ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, AdminContext $admin_context) {
|
Chris@0
|
58 $this->user = $user;
|
Chris@0
|
59 $this->configFactory = $config_factory;
|
Chris@0
|
60 $this->entityManager = $entity_manager;
|
Chris@0
|
61 $this->adminContext = $admin_context;
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 /**
|
Chris@0
|
65 * {@inheritdoc}
|
Chris@0
|
66 */
|
Chris@0
|
67 public function applies(RouteMatchInterface $route_match) {
|
Chris@0
|
68 return ($this->entityManager->hasHandler('user_role', 'storage') && $this->user->hasPermission('view the administration theme') && $this->adminContext->isAdminRoute($route_match->getRouteObject()));
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * {@inheritdoc}
|
Chris@0
|
73 */
|
Chris@0
|
74 public function determineActiveTheme(RouteMatchInterface $route_match) {
|
Chris@0
|
75 return $this->configFactory->get('system.theme')->get('admin');
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 }
|