Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Theme/ThemeAccessCheck.php \Drupal\Core\Theme\ThemeAccessCheck
  2. 9 core/lib/Drupal/Core/Theme/ThemeAccessCheck.php \Drupal\Core\Theme\ThemeAccessCheck

Provides access checking for themes for routing and theme negotiation.

Hierarchy

Expanded class hierarchy of ThemeAccessCheck

1 string reference to 'ThemeAccessCheck'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ThemeAccessCheck
access_check.theme in core/core.services.yml
Drupal\Core\Theme\ThemeAccessCheck

File

core/lib/Drupal/Core/Theme/ThemeAccessCheck.php, line 12

Namespace

Drupal\Core\Theme
View source
class ThemeAccessCheck implements AccessInterface {

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * Constructs a \Drupal\Core\Theme\Registry object.
   *
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   */
  public function __construct(ThemeHandlerInterface $theme_handler) {
    $this->themeHandler = $theme_handler;
  }

  /**
   * Checks access to the theme for routing.
   *
   * @param string $theme
   *   The name of a theme.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access($theme) {

    // Cacheable until the theme settings are modified.
    return AccessResult::allowedIf($this
      ->checkAccess($theme))
      ->addCacheTags([
      'config:' . $theme . '.settings',
    ]);
  }

  /**
   * Indicates whether the theme is accessible based on whether it is installed.
   *
   * @param string $theme
   *   The name of a theme.
   *
   * @return bool
   *   TRUE if the theme is installed, FALSE otherwise.
   */
  public function checkAccess($theme) {
    $themes = $this->themeHandler
      ->listInfo();
    return !empty($themes[$theme]->status);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeAccessCheck::$themeHandler protected property The theme handler.
ThemeAccessCheck::access public function Checks access to the theme for routing.
ThemeAccessCheck::checkAccess public function Indicates whether the theme is accessible based on whether it is installed.
ThemeAccessCheck::__construct public function Constructs a \Drupal\Core\Theme\Registry object.