class AdminNegotiator

Same name and namespace in other branches
  1. 11.x core/modules/user/src/Theme/AdminNegotiator.php \Drupal\user\Theme\AdminNegotiator
  2. 10 core/modules/user/src/Theme/AdminNegotiator.php \Drupal\user\Theme\AdminNegotiator
  3. 9 core/modules/user/src/Theme/AdminNegotiator.php \Drupal\user\Theme\AdminNegotiator
  4. 8.9.x 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 file declares its use of AdminNegotiator
AdminNegotiatorTest.php in core/modules/user/tests/src/Unit/Theme/AdminNegotiatorTest.php
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 16

Namespace

Drupal\user\Theme
View source
class AdminNegotiator implements ThemeNegotiatorInterface {
  use DeprecatedServicePropertyTrait;
  
  /**
   * The service properties that should raise a deprecation error.
   */
  private array $deprecatedProperties = [
    'entityTypeManager' => 'entity_type.manager',
  ];
  public function __construct(protected AccountInterface $user, protected ConfigFactoryInterface $configFactory, #[Autowire(service: 'router.admin_context')] protected AdminContext $adminContext) {
  }
  
  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    $is_admin_route = $this->adminContext
      ->isAdminRoute($route_match->getRouteObject());
    return $is_admin_route && $this->user
      ->hasPermission('view the administration theme');
  }
  
  /**
   * {@inheritdoc}
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    return $this->configFactory
      ->get('system.theme')
      ->get('admin') ?: NULL;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AdminNegotiator::$deprecatedProperties private property The service properties that should raise a deprecation error.
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
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.