annotate core/modules/user/src/Theme/AdminNegotiator.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
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@18 6 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
Chris@18 7 use Drupal\Core\Entity\EntityTypeManagerInterface;
Chris@0 8 use Drupal\Core\Routing\AdminContext;
Chris@0 9 use Drupal\Core\Routing\RouteMatchInterface;
Chris@0 10 use Drupal\Core\Session\AccountInterface;
Chris@0 11 use Drupal\Core\Theme\ThemeNegotiatorInterface;
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Sets the active theme on admin pages.
Chris@0 15 */
Chris@0 16 class AdminNegotiator implements ThemeNegotiatorInterface {
Chris@18 17 use DeprecatedServicePropertyTrait;
Chris@18 18
Chris@18 19 /**
Chris@18 20 * {@inheritdoc}
Chris@18 21 */
Chris@18 22 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
Chris@0 23
Chris@0 24 /**
Chris@0 25 * The current user.
Chris@0 26 *
Chris@0 27 * @var \Drupal\Core\Session\AccountInterface
Chris@0 28 */
Chris@0 29 protected $user;
Chris@0 30
Chris@0 31 /**
Chris@0 32 * The config factory.
Chris@0 33 *
Chris@0 34 * @var \Drupal\Core\Config\ConfigFactoryInterface
Chris@0 35 */
Chris@0 36 protected $configFactory;
Chris@0 37
Chris@0 38 /**
Chris@18 39 * The entity type manager.
Chris@0 40 *
Chris@18 41 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
Chris@0 42 */
Chris@18 43 protected $entityTypeManager;
Chris@0 44
Chris@0 45 /**
Chris@0 46 * The route admin context to determine whether a route is an admin one.
Chris@0 47 *
Chris@0 48 * @var \Drupal\Core\Routing\AdminContext
Chris@0 49 */
Chris@0 50 protected $adminContext;
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Creates a new AdminNegotiator instance.
Chris@0 54 *
Chris@0 55 * @param \Drupal\Core\Session\AccountInterface $user
Chris@0 56 * The current user.
Chris@0 57 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
Chris@0 58 * The config factory.
Chris@18 59 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
Chris@18 60 * The entity type manager.
Chris@0 61 * @param \Drupal\Core\Routing\AdminContext $admin_context
Chris@0 62 * The route admin context to determine whether the route is an admin one.
Chris@0 63 */
Chris@18 64 public function __construct(AccountInterface $user, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, AdminContext $admin_context) {
Chris@0 65 $this->user = $user;
Chris@0 66 $this->configFactory = $config_factory;
Chris@18 67 $this->entityTypeManager = $entity_type_manager;
Chris@0 68 $this->adminContext = $admin_context;
Chris@0 69 }
Chris@0 70
Chris@0 71 /**
Chris@0 72 * {@inheritdoc}
Chris@0 73 */
Chris@0 74 public function applies(RouteMatchInterface $route_match) {
Chris@18 75 return ($this->entityTypeManager->hasHandler('user_role', 'storage') && $this->user->hasPermission('view the administration theme') && $this->adminContext->isAdminRoute($route_match->getRouteObject()));
Chris@0 76 }
Chris@0 77
Chris@0 78 /**
Chris@0 79 * {@inheritdoc}
Chris@0 80 */
Chris@0 81 public function determineActiveTheme(RouteMatchInterface $route_match) {
Chris@0 82 return $this->configFactory->get('system.theme')->get('admin');
Chris@0 83 }
Chris@0 84
Chris@0 85 }