diff --git a/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php index cfb06ce..7253b54 100644 --- a/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -97,8 +97,8 @@ public function readMultiple(array $names) { $cids = $this->getCacheKeys($names); $cached_list = $this->cache->getMultiple($cids); - if (!empty($names)) { - $list = $this->storage->readMultiple($names); + if (!empty($cids)) { + $list = $this->storage->readMultiple(array_keys($cids)); // Cache configuration objects that were loaded from the storage, cache // missing configuration objects as an explicit FALSE. foreach ($names as $name) { @@ -275,4 +275,14 @@ protected function getCacheKeys(array $names) { return $cids; } + /** + * Set the cache prefix used by this storage. + * + * @param string $cachePrefix + * Name of the prefix that should be used for all cache IDs. + */ + public function setCachePrefix($cachePrefix) { + $this->cachePrefix = $cachePrefix; + } + } diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index ec2d2f2..d1197d7 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -138,12 +138,12 @@ public function installDefaultConfig($type, $name) { // Remove configuration that already exists in the active storage. $sorted_config = array_diff($sorted_config, $this->activeStorage->listAll()); - foreach ($sorted_config as $name) { - $new_config = new Config($name, $this->activeStorage, $this->eventDispatcher, $this->typedConfig); - if ($data[$name] !== FALSE) { - $new_config->setData($data[$name]); + foreach ($sorted_config as $config_name) { + $new_config = new Config($config_name, $this->activeStorage, $this->eventDispatcher, $this->typedConfig); + if ($data[$config_name] !== FALSE) { + $new_config->setData($data[$config_name]); } - if ($entity_type = $this->configManager->getEntityTypeIdByName($name)) { + if ($entity_type = $this->configManager->getEntityTypeIdByName($config_name)) { // If we are syncing do not create configuration entities. Pluggable // configuration entities can have dependencies on modules that are @@ -159,8 +159,8 @@ public function installDefaultConfig($type, $name) { ->getStorage($entity_type); // It is possible that secondary writes can occur during configuration // creation. Updates of such configuration are allowed. - if ($this->activeStorage->exists($name)) { - $id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix()); + if ($this->activeStorage->exists($config_name)) { + $id = $entity_storage->getIDFromConfigName($config_name, $entity_storage->getEntityType()->getConfigPrefix()); $entity = $entity_storage->load($id); foreach ($new_config->get() as $property => $value) { $entity->set($property, $value); diff --git a/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php index 9a1eb2e..37bdf9e 100644 --- a/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php +++ b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php @@ -80,7 +80,7 @@ public function loadOverrides($names) { public function getOverride($langcode, $name) { $storage = clone $this->storage; $data = $storage->setLangcode($langcode)->read($name); - $override = new LanguageConfigOverride($name, $this->storage, $this->typedConfigManager); + $override = new LanguageConfigOverride($name, $storage, $this->typedConfigManager); if (!empty($data)) { $override->initWithData($data); } diff --git a/core/modules/language/lib/Drupal/language/Config/LanguageOverrideCachedStorage.php b/core/modules/language/lib/Drupal/language/Config/LanguageOverrideCachedStorage.php index 40983d6..4026102 100644 --- a/core/modules/language/lib/Drupal/language/Config/LanguageOverrideCachedStorage.php +++ b/core/modules/language/lib/Drupal/language/Config/LanguageOverrideCachedStorage.php @@ -43,4 +43,13 @@ public function setLangcode($langcode) { return $this; } + /** + * {@inheritdoc} + */ + function __clone() { + // Also clone the inner storage, so that language code changes work as + // expected. + $this->storage = clone $this->storage; + } + } diff --git a/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php b/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php index 6c60af4..c7d8dc3 100644 --- a/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php @@ -84,6 +84,33 @@ public function testGetMultipleOnPrimedCache() { } /** + * Test that the cache prefix is used correctly. + */ + public function testGetMultipleCachePrefix() { + $configNames = array( + 'foo.bar', + 'baz.back', + ); + $configCacheValues = array( + 'prefix:foo.bar' => array( + 'foo' => 'bar', + ), + 'prefix:baz.back' => array( + 'foo' => 'bar', + ), + ); + $storage = $this->getMock('Drupal\Core\Config\StorageInterface'); + $storage->expects($this->never())->method('readMultiple'); + $cache = new MemoryBackend(__FUNCTION__); + foreach ($configCacheValues as $key => $value) { + $cache->set($key, $value); + } + $cachedStorage = new CachedStorage($storage, $cache); + $cachedStorage->setCachePrefix('prefix'); + $this->assertEquals($configCacheValues, $cachedStorage->readMultiple($configNames)); + } + + /** * Test fall through to file storage in CachedStorage::readMulitple(). */ public function testGetMultipleOnPartiallyPrimedCache() { @@ -116,7 +143,7 @@ public function testGetMultipleOnPartiallyPrimedCache() { $storage = $this->getMock('Drupal\Core\Config\StorageInterface'); $storage->expects($this->once()) ->method('readMultiple') - ->with(array(2 => $configNames[2], 4 => $configNames[4])) + ->with(array($configNames[2], $configNames[4])) ->will($this->returnValue($response)); $cachedStorage = new CachedStorage($storage, $cache);