class ThemeCacheContext
Same name in other branches
- 9 core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php \Drupal\Core\Cache\Context\ThemeCacheContext
- 8.9.x core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php \Drupal\Core\Cache\Context\ThemeCacheContext
- 10 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
- class \Drupal\Core\Cache\Context\ThemeCacheContext implements \Drupal\Core\Cache\Context\CacheContextInterface
Expanded class hierarchy of 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 | Overrides CacheContextInterface::getCacheableMetadata | |
ThemeCacheContext::getContext | public | function | Overrides CacheContextInterface::getContext | |
ThemeCacheContext::getLabel | public static | function | 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.