You are here

class AdminNegotiator in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Theme/AdminNegotiator.php \Drupal\user\Theme\AdminNegotiator

Sets the active theme on admin pages.

Hierarchy

Expanded class hierarchy of AdminNegotiator

1 string reference to 'AdminNegotiator'
user.services.yml in core/modules/user/user.services.yml
core/modules/user/user.services.yml
1 service uses AdminNegotiator
theme.negotiator.admin_theme in core/modules/user/user.services.yml
Drupal\user\Theme\AdminNegotiator

File

core/modules/user/src/Theme/AdminNegotiator.php, line 20
Contains \Drupal\user\Theme\AdminNegotiator.

Namespace

Drupal\user\Theme
View source
class AdminNegotiator implements ThemeNegotiatorInterface {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $user;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * The route admin context to determine whether a route is an admin one.
   *
   * @var \Drupal\Core\Routing\AdminContext
   */
  protected $adminContext;

  /**
   * Creates a new AdminNegotiator instance.
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   The current user.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(AccountInterface $user, ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, AdminContext $admin_context) {
    $this->user = $user;
    $this->configFactory = $config_factory;
    $this->entityManager = $entity_manager;
    $this->adminContext = $admin_context;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    return $this->entityManager
      ->hasHandler('user_role', 'storage') && $this->user
      ->hasPermission('view the administration theme') && $this->adminContext
      ->isAdminRoute($route_match
      ->getRouteObject());
  }

  /**
   * {@inheritdoc}
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    return $this->configFactory
      ->get('system.theme')
      ->get('admin');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminNegotiator::$adminContext protected property The route admin context to determine whether a route is an admin one.
AdminNegotiator::$configFactory protected property The config factory.
AdminNegotiator::$entityManager protected property The entity manager.
AdminNegotiator::$user protected property The current user.
AdminNegotiator::applies public function Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface::applies
AdminNegotiator::determineActiveTheme public function Determine the active theme for the request. Overrides ThemeNegotiatorInterface::determineActiveTheme
AdminNegotiator::__construct public function Creates a new AdminNegotiator instance.