diff -u b/core/includes/bootstrap.inc b/core/includes/bootstrap.inc --- b/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2624,8 +2624,8 @@ // Allow modules to react on language system initialization in multilingual // environments. bootstrap_invoke_all('language_init'); - // @TODO remove after http://drupal.org/node/1859110 is resolved. - drupal_container()->get('config.factory')->resetConfig(); + // @todo D8: Remove after http://drupal.org/node/1859110. + drupal_container()->get('config.factory')->reset(); } } diff -u b/core/includes/config.inc b/core/includes/config.inc --- b/core/includes/config.inc +++ b/core/includes/config.inc @@ -189,7 +189,7 @@ $data = $source_storage->read($name); $target_storage->write($name, $data); } - $factory->resetConfig($name); + $factory->reset($name); } } } diff -u b/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php --- b/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -194,15 +194,18 @@ * The configuration object. */ public function setData(array $data) { + $this->replaceData($data); // A load would destroy the data just set (for example on import). $this->isLoaded = TRUE; - return $this->setDataReal($data); + return $this; } /** * Replaces the data of this configuration object. * - * This function is separate from setData to avoid load() state tracking. + * This function is separate from setData() to avoid load() state tracking. + * A load() would destroy the replaced data (for example on import). Do not + * call set() when inside load(). * * @param array $data * The new configuration data. @@ -210,9 +213,7 @@ * @return Drupal\Core\Config\Config * The configuration object. */ - protected function setDataReal(array $data) { - // A load would destroy the data just set (for example on import). Do not - // set when inside load(). + protected function replaceData(array $data) { $this->data = $data; $this->resetOverriddenData(); return $this; @@ -371,11 +372,11 @@ $data = $this->storage->read($this->name); if ($data === FALSE) { $this->isNew = TRUE; - $this->setDataReal(array()); + $this->replaceData(array()); } else { $this->isNew = FALSE; - $this->setDataReal($data); + $this->replaceData($data); } $this->notify('load'); $this->isLoaded = TRUE; @@ -461,8 +462,7 @@ $this->load(); } // Preserve integer keys so that config keys are not changed. - $this->data = NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE); - $this->resetOverriddenData(); + $this->replaceData(NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE)); return $this; } } diff -u b/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php --- b/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -38,7 +38,12 @@ */ protected $eventDispatcher; - protected $configs = array(); + /** + * Cached configuration objects. + * + * @var array + */ + protected $cache = array(); /** * Constructs the Config factory. @@ -66,50 +71,53 @@ public function get($name) { global $conf; - if (isset($this->configs[$name])) { - return $this->configs[$name]; + if (isset($this->cache[$name])) { + return $this->cache[$name]; } - $this->configs[$name] = new Config($name, $this->storage, $this->eventDispatcher); - return $this->configs[$name]->init(); + $this->cache[$name] = new Config($name, $this->storage, $this->eventDispatcher); + return $this->cache[$name]->init(); } /** - * Reset config objects. Internal only. + * Resets and re-initializes configuration objects. Internal use only. * * @param string $name - * The name of the object to reset. If NULL then all objects are reset. + * (optional) The name of the configuration object to reset. If omitted, all + * configuration objects are reset. */ - public function resetConfig($name = NULL) { + public function reset($name = NULL) { if ($name) { - if (isset($this->configs[$name])) { - $this->configs[$name]->init(); + if (isset($this->cache[$name])) { + $this->cache[$name]->init(); } } else { - foreach ($this->configs as $config) { + foreach ($this->cache as $config) { $config->init(); } } } /** - * @todo: remove after http://drupal.org/node/1865206. + * Renames a configuration object in the cache. + * + * @param string $old_name + * The old name of the configuration object. + * @param string $new_name + * The new name of the configuration object. * - * @param $old_name - * @param $new_name + * @todo D8: Remove after http://drupal.org/node/1865206. */ - public function renameConfig($old_name, $new_name) { - // This will likely always be TRUE - if (isset($this->configs[$old_name])) { - $config = $this->configs[$old_name]; - // Save a clone of the config object in the old slot - $this->configs[$old_name] = clone $config; + public function rename($old_name, $new_name) { + if (isset($this->cache[$old_name])) { + $config = $this->cache[$old_name]; + // Clone the object into the existing slot. + $this->cache[$old_name] = clone $config; - // Update the name and re-init the object - // then save it in the slot of the new_name + // Change the object's name and re-initialize it. $config->setName($new_name)->init(); - $this->configs[$new_name] = $config; + $this->cache[$new_name] = $config; } } } diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -289,12 +289,12 @@ $config = config($prefix . $id); $is_new = $config->isNew(); - if ($id != $entity->id()) { - // We need to keep three things in mind for a rename: - // * Storage controller needs to access the original object - // * Object should be renamed in ConfigFactory and slot should be updated - // * All instances of the Object should be renamed - drupal_container()->get('config.factory')->renameConfig($prefix . $id, $prefix . $entity->id()); + if ($id !== $entity->id()) { + // Renaming a config object needs to cater for: + // - Storage controller needs to access the original object. + // - The object needs to be renamed/copied in ConfigFactory and reloaded. + // - All instances of the object need to be renamed. + drupal_container()->get('config.factory')->rename($prefix . $id, $prefix . $entity->id()); } if (!$is_new && !isset($entity->original)) { diff -u b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -808,6 +808,7 @@ global $conf; cache('bootstrap')->delete('variables'); $conf = variable_initialize(); + drupal_container()->get('config.factory')->reset(); } /** @@ -1227,7 +1228,6 @@ $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers)); // Ensure that any changes to variables in the other thread are picked up. $this->refreshVariables(); - drupal_container()->get('config.factory')->resetConfig(); // Replace original page output with new output from redirected page(s). if ($new = $this->checkForMetaRefresh()) {