function ConfigFactory::onConfigSave

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/ConfigFactory.php \Drupal\Core\Config\ConfigFactory::onConfigSave()
  2. 10 core/lib/Drupal/Core/Config/ConfigFactory.php \Drupal\Core\Config\ConfigFactory::onConfigSave()
  3. 11.x core/lib/Drupal/Core/Config/ConfigFactory.php \Drupal\Core\Config\ConfigFactory::onConfigSave()

Updates stale static cache entries when configuration is saved.

Parameters

ConfigCrudEvent $event: The configuration event.

File

core/lib/Drupal/Core/Config/ConfigFactory.php, line 337

Class

ConfigFactory
Defines the configuration object factory.

Namespace

Drupal\Core\Config

Code

public function onConfigSave(ConfigCrudEvent $event) {
    $saved_config = $event->getConfig();
    // We are only concerned with config objects that belong to the collection
    // that matches the storage we depend on. Skip if the event was fired for a
    // config object belonging to a different collection.
    if ($saved_config->getStorage()
        ->getCollectionName() !== $this->storage
        ->getCollectionName()) {
        return;
    }
    // Ensure that the static cache contains up to date configuration objects by
    // replacing the data on any entries for the configuration object apart
    // from the one that references the actual config object being saved.
    foreach ($this->getConfigCacheKeys($saved_config->getName()) as $cache_key) {
        $cached_config = $this->cache[$cache_key];
        if ($cached_config !== $saved_config) {
            // We can not just update the data since other things about the object
            // might have changed. For example, whether or not it is new.
            $this->cache[$cache_key]
                ->initWithData($saved_config->getRawData());
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.