You are here

class ThemeCacheContext in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php \Drupal\Core\Cache\Context\ThemeCacheContext

Defines the ThemeCacheContext service, for "per theme" caching.

Cache context ID: 'theme'.

Hierarchy

Expanded class hierarchy of ThemeCacheContext

1 string reference to 'ThemeCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ThemeCacheContext
cache_context.theme in core/core.services.yml
Drupal\Core\Cache\Context\ThemeCacheContext

File

core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php, line 13

Namespace

Drupal\Core\Cache\Context
View source
class ThemeCacheContext implements CacheContextInterface {

  /**
   * The theme manager.
   *
   * @var \Drupal\Core\Theme\ThemeManagerInterface
   */
  protected $themeManager;

  /**
   * Constructs a new ThemeCacheContext service.
   *
   * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
   *   The theme manager.
   */
  public function __construct(ThemeManagerInterface $theme_manager) {
    $this->themeManager = $theme_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Theme');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return $this->themeManager
      ->getActiveTheme()
      ->getName() ?: 'stark';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeCacheContext::$themeManager protected property The theme manager.
ThemeCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
ThemeCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
ThemeCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
ThemeCacheContext::__construct public function Constructs a new ThemeCacheContext service.