You are here

public function ConfigCacheTag::onSave in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 54
Contains \Drupal\system\EventSubscriber\ConfigCacheTag.

Class

ConfigCacheTag
A subscriber invalidating cache tags when system config objects are saved.

Namespace

Drupal\system\EventSubscriber

Code

public function onSave(ConfigCrudEvent $event) {

  // 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 ($event
    ->getConfig()
    ->getName() === 'system.site') {
    $this->cacheTagsInvalidator
      ->invalidateTags([
      'route_match',
      'rendered',
    ]);
  }

  // Theme configuration and global theme settings.
  if (in_array($event
    ->getConfig()
    ->getName(), [
    'system.theme',
    'system.theme.global',
  ], TRUE)) {
    $this->cacheTagsInvalidator
      ->invalidateTags([
      'rendered',
    ]);
  }

  // Theme-specific settings, check if this matches a theme settings
  // configuration object, in that case, clear the rendered cache tag.
  foreach (array_keys($this->themeHandler
    ->listInfo()) as $theme_name) {
    if ($theme_name == $event
      ->getConfig()
      ->getName()) {
      $this->cacheTagsInvalidator
        ->invalidateTags([
        'rendered',
      ]);
      break;
    }
  }
}