class ThemeCacheContext
Defines the ThemeCacheContext service, for "per theme" caching.
Cache context ID: 'theme'.
Hierarchy
- class \Drupal\Core\Cache\Context\ThemeCacheContext implements \Drupal\Core\Cache\Context\CacheContextInterface
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
File
- 
              core/lib/ Drupal/ Core/ Cache/ Context/ ThemeCacheContext.php, line 13 
Namespace
Drupal\Core\Cache\ContextView 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
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | 
|---|---|---|---|---|
| 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. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
