class ConfigCacheTag
Same name in other branches
- 9 core/modules/system/src/EventSubscriber/ConfigCacheTag.php \Drupal\system\EventSubscriber\ConfigCacheTag
- 8.9.x core/modules/system/src/EventSubscriber/ConfigCacheTag.php \Drupal\system\EventSubscriber\ConfigCacheTag
- 11.x core/modules/system/src/EventSubscriber/ConfigCacheTag.php \Drupal\system\EventSubscriber\ConfigCacheTag
A subscriber invalidating cache tags when system config objects are saved.
Hierarchy
- class \Drupal\system\EventSubscriber\ConfigCacheTag implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigCacheTag
1 string reference to 'ConfigCacheTag'
- system.services.yml in core/
modules/ system/ system.services.yml - core/modules/system/system.services.yml
1 service uses ConfigCacheTag
- system.config_cache_tag in core/
modules/ system/ system.services.yml - Drupal\system\EventSubscriber\ConfigCacheTag
File
-
core/
modules/ system/ src/ EventSubscriber/ ConfigCacheTag.php, line 15
Namespace
Drupal\system\EventSubscriberView source
class ConfigCacheTag implements EventSubscriberInterface {
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/**
* Constructs a ConfigCacheTag object.
*
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
* @param \Drupal\Core\Theme\Registry|null $themeRegistry
* The theme registry.
*/
public function __construct(ThemeHandlerInterface $theme_handler, CacheTagsInvalidatorInterface $cache_tags_invalidator, ?Registry $themeRegistry = NULL) {
$this->themeHandler = $theme_handler;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
if ($this->themeRegistry === NULL) {
@trigger_error('Calling ' . __METHOD__ . '() without the $themeRegistry argument is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3355227', E_USER_DEPRECATED);
$this->themeRegistry = \Drupal::service('theme.registry');
}
}
/**
* Invalidate cache tags when particular system config objects are saved.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The Event to process.
*/
public function onSave(ConfigCrudEvent $event) {
$config_name = $event->getConfig()
->getName();
// Changing the site settings may mean a different route is selected for the
// front page. Additionally a change to the site name or similar must
// invalidate the render cache since this could be used anywhere.
if ($config_name === 'system.site') {
$this->cacheTagsInvalidator
->invalidateTags([
'route_match',
'rendered',
]);
}
// Theme configuration and global theme settings.
if (in_array($config_name, [
'system.theme',
'system.theme.global',
], TRUE)) {
$this->cacheTagsInvalidator
->invalidateTags([
'rendered',
]);
}
// Library and template overrides potentially change for the default theme
// when the admin theme is changed.
if ($config_name === 'system.theme' && $event->isChanged('admin')) {
$this->themeRegistry
->reset();
$this->cacheTagsInvalidator
->invalidateTags([
'library_info',
]);
}
// Theme-specific settings, check if this matches a theme settings
// configuration object (THEME_NAME.settings), in that case, clear the
// rendered cache tag.
if (preg_match('/^([^\\.]*)\\.settings$/', $config_name, $matches)) {
if ($this->themeHandler
->themeExists($matches[1])) {
$this->cacheTagsInvalidator
->invalidateTags([
'rendered',
]);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[ConfigEvents::SAVE][] = [
'onSave',
];
return $events;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ConfigCacheTag::$cacheTagsInvalidator | protected | property | The cache tags invalidator. |
ConfigCacheTag::$themeHandler | protected | property | The theme handler. |
ConfigCacheTag::getSubscribedEvents | public static | function | |
ConfigCacheTag::onSave | public | function | Invalidate cache tags when particular system config objects are saved. |
ConfigCacheTag::__construct | public | function | Constructs a ConfigCacheTag object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.