diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 6ec8a5c..c56dfe8 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -111,25 +111,26 @@ protected function doGet($name, $immutable = TRUE) { } 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, $immutable); - $this->cache[$cache_key] = $this->createConfigObject($name, $immutable); + // storage, create a new object. + $config = $this->createConfigObject($name, $immutable); if ($immutable) { // Get and apply any overrides. $overrides = $this->loadOverrides(array($name)); if (isset($overrides[$name])) { - $this->cache[$cache_key]->setModuleOverride($overrides[$name]); + $config->setModuleOverride($overrides[$name]); } // Apply any settings.php overrides. if (isset($GLOBALS['config'][$name])) { - $this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]); + $config->setSettingsOverride($GLOBALS['config'][$name]); } } - $this->propagateConfigOverrideCacheability($cache_key, $name); + foreach ($this->configFactoryOverrides as $override) { + $config->addCacheableDependency($override->getCacheableMetadata($name)); + } - return $this->cache[$cache_key]; + return $config; } } diff --git a/core/modules/config/src/Tests/ConfigCRUDTest.php b/core/modules/config/src/Tests/ConfigCRUDTest.php index 6258ccc..e127892 100644 --- a/core/modules/config/src/Tests/ConfigCRUDTest.php +++ b/core/modules/config/src/Tests/ConfigCRUDTest.php @@ -150,6 +150,12 @@ function testCRUD() { $new_config->save(); $this->assertIdentical($new_config->get('value'), $expected_values['value']); $this->assertIdentical($new_config->get('404'), $expected_values['404']); + + // Test that getMultiple() does not return new config objects that were + // previously accessed with get() + $new_config = $config_factory->get('non_existing_key'); + $this->assertTrue($new_config->isNew()); + $this->assertEqual(0, count($config_factory->loadMultiple(['non_existing_key'])), 'loadMultiple() does not return new objects'); } /** diff --git a/core/modules/config/src/Tests/ConfigOverrideTest.php b/core/modules/config/src/Tests/ConfigOverrideTest.php index 4b2e908..b9a262d 100644 --- a/core/modules/config/src/Tests/ConfigOverrideTest.php +++ b/core/modules/config/src/Tests/ConfigOverrideTest.php @@ -132,6 +132,8 @@ function testConfOverride() { ->save(); // Ensure override is preserved but all other data has been updated // accordingly. + $config = \Drupal::config('config_test.new'); + $this->assertFalse($config->isNew(), 'The configuration object config_test.new is not new'); $this->assertIdentical($config->get('key'), 'override'); $this->assertIdentical($config->get('new_key'), 'new_value'); $raw_data = $config->getRawData();