diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 970a500..790b395 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -109,27 +109,20 @@ public function get($name) { return $config[$name]; } else { + // If the configuration object does not exist in the configuration + // storage, create a new object and add it to the static cache. $cache_key = $this->getConfigCacheKey($name); - // If the config object has been deleted it will already exist in the - // cache but self::loadMultiple does not return such objects. - // @todo Explore making ConfigFactory a listener to the config.delete - // event to reset the static cache when this occurs. - if (!isset($this->cache[$cache_key])) { - // If the configuration object does not exist in the configuration - // storage or static cache create a new object and add it to the static - // cache. - $this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->typedConfigManager); + $this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->typedConfigManager); - if ($this->useOverrides) { - // Get and apply any overrides. - $overrides = $this->loadOverrides(array($name)); - if (isset($overrides[$name])) { - $this->cache[$cache_key]->setModuleOverride($overrides[$name]); - } - // Apply any settings.php overrides. - if (isset($GLOBALS['config'][$name])) { - $this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]); - } + if ($this->useOverrides) { + // Get and apply any overrides. + $overrides = $this->loadOverrides(array($name)); + if (isset($overrides[$name])) { + $this->cache[$cache_key]->setModuleOverride($overrides[$name]); + } + // Apply any settings.php overrides. + if (isset($GLOBALS['config'][$name])) { + $this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]); } } return $this->cache[$cache_key]; @@ -143,10 +136,8 @@ public function loadMultiple(array $names) { $list = array(); foreach ($names as $key => $name) { - // @todo: Deleted configuration stays in $this->cache, only return - // configuration objects that are not new. $cache_key = $this->getConfigCacheKey($name); - if (isset($this->cache[$cache_key]) && !$this->cache[$cache_key]->isNew()) { + if (isset($this->cache[$cache_key])) { $list[$name] = $this->cache[$cache_key]; unset($names[$key]); } @@ -319,10 +310,24 @@ public function onConfigSave(ConfigCrudEvent $event) { } /** + * Removes stale static cache entries when configuration is deleted. + * + * @param \Drupal\Core\Config\ConfigCrudEvent $event + * The configuration event. + */ + public function onConfigDelete(ConfigCrudEvent $event) { + // Ensure that the static cache does not contain deleted configuration. + foreach ($this->getConfigCacheKeys($event->getConfig()->getName()) as $cache_key) { + unset($this->cache[$cache_key]); + } + } + + /** * {@inheritdoc} */ static function getSubscribedEvents() { $events[ConfigEvents::SAVE][] = array('onConfigSave', 255); + $events[ConfigEvents::DELETE][] = array('onConfigDelete', 255); return $events; } diff --git a/core/modules/config/src/Tests/ConfigCRUDTest.php b/core/modules/config/src/Tests/ConfigCRUDTest.php index 4c3642e..74b0d85 100644 --- a/core/modules/config/src/Tests/ConfigCRUDTest.php +++ b/core/modules/config/src/Tests/ConfigCRUDTest.php @@ -72,6 +72,11 @@ function testCRUD() { $this->assertIdentical($new_config->get(), $config->get()); $this->assertIdentical($config->isNew(), FALSE); + // Pollute the config factory static cache. + $this->container->get('config.factory')->setOverrideState(FALSE); + \Drupal::config($name); + $this->container->get('config.factory')->setOverrideState(TRUE); + // Delete the configuration object. $config->delete(); @@ -79,6 +84,12 @@ function testCRUD() { $this->assertIdentical($config->get(), array()); $this->assertIdentical($config->isNew(), TRUE); + // Verify that all copies of the configuration has been removed from the + // static cache. + $this->container->get('config.factory')->setOverrideState(FALSE); + $this->assertIdentical(\Drupal::config($name)->isNew(), TRUE); + $this->container->get('config.factory')->setOverrideState(TRUE); + // Verify the active configuration contains no value. $actual_data = $storage->read($name); $this->assertIdentical($actual_data, FALSE); diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 0c33fd2..770f368 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -215,7 +215,7 @@ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_ // Delete the existing editor if disabling or switching between editors. $format_id = $form_state->getFormObject()->getEntity()->id(); $original_editor = editor_load($format_id); - if ($original_editor && $original_editor->getEditor() != $form_state->getValue('editor')) { + if ($original_editor && $original_editor->getEditor() != $form_state->getValue(array('editor', 'editor'))) { $original_editor->delete(); }