function ConfigCacheTag::onSave
Same name in other branches
- 9 core/modules/system/src/EventSubscriber/ConfigCacheTag.php \Drupal\system\EventSubscriber\ConfigCacheTag::onSave()
- 8.9.x core/modules/system/src/EventSubscriber/ConfigCacheTag.php \Drupal\system\EventSubscriber\ConfigCacheTag::onSave()
- 10 core/modules/system/src/EventSubscriber/ConfigCacheTag.php \Drupal\system\EventSubscriber\ConfigCacheTag::onSave()
Invalidate cache tags when particular system config objects are saved.
Parameters
\Drupal\Core\Config\ConfigCrudEvent $event: The Event to process.
File
-
core/
modules/ system/ src/ EventSubscriber/ ConfigCacheTag.php, line 33
Class
- ConfigCacheTag
- A subscriber invalidating cache tags when system config objects are saved.
Namespace
Drupal\system\EventSubscriberCode
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',
]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.