class ThemeCacheContext in Drupal 8
Same name and namespace in other branches
- 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
- class \Drupal\Core\Cache\Context\ThemeCacheContext implements 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemeCacheContext:: |
protected | property | The theme manager. | |
ThemeCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
ThemeCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
ThemeCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
ThemeCacheContext:: |
public | function | Constructs a new ThemeCacheContext service. |