Skip to content
Snippets Groups Projects
Commit 9980bd0f authored by catch's avatar catch
Browse files

Issue #2598232 by Berdir, alexpott, juanse254: ConfigFactory::get() pollutes...

Issue #2598232 by Berdir, alexpott, juanse254: ConfigFactory::get() pollutes ::loadMultiple() static cache with new config objects
parent 3c51b6b7
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
......
......@@ -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');
}
/**
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment