comparison core/modules/user/src/Theme/AdminNegotiator.php @ 0:4c8ae668cc8c

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