diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 9d7b584..1641641 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -184,25 +184,35 @@ protected function doLoadMultiple(array $ids = NULL) { } // Load all of the configuration entities. - $records = array(); + /** @var Config[] $configs */ + $configs = []; + $records = []; foreach ($this->configFactory->loadMultiple($names) as $config) { $id = $config->get($this->idKey); $records[$id] = $this->overrideFree ? $config->getOriginal(NULL, FALSE) : $config->get(); - - // Add cacheability metadata to the record. - $records[$id]['cacheContexts'] = $config->getCacheContexts(); - $records[$id]['cacheTags'] = $config->getCacheTags(); - $records[$id]['cacheMaxAge'] = $config->getCacheMaxAge(); - - // Remove the self-referring cache tag that is present on Config objects, - // a ConfigEntity doesn't need this since it will be dynamically generated - // in EntityInterface::getCacheTagsToInvalidate(). The cache tags are - // merged during rendering, and having fewer tags available improves - // performance. - $key = array_search('config:' . $config->getName(), $records[$id]['cacheTags']); - unset($records[$id]['cacheTags'][$key]); + $configs[$id] = $config; + } + $entities = $this->mapFromStorageRecords($records, $configs); + + // Add cacheability metadata to the entities. + foreach ($entities as $id => $entity) { + $entity->addCacheContexts($configs[$id]->getCacheContexts()); + $entity->mergeCacheMaxAge($configs[$id]->getCacheMaxAge()); + + // Remove the self-referring cache tag that is present on Config objects + // before setting it. A ConfigEntity doesn't need this since it will be + // dynamically generated in EntityInterface::getCacheTagsToInvalidate(). + // The cache tags are merged during rendering, and having fewer tags + // available improves performance. + $cache_tags = $config->getCacheTags(); + $key = array_search('config:' . $configs[$id]->getName(), $cache_tags); + if ($key !== FALSE) { + unset($cache_tags[$key]); + } + $entity->addCacheTags($cache_tags); } - return $this->mapFromStorageRecords($records); + + return $entities; } /** diff --git a/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php b/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php index a74254b..ba774bb 100644 --- a/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php +++ b/core/modules/config/src/Tests/CacheabilityMetadataConfigOverrideIntegrationTest.php @@ -53,7 +53,7 @@ public function testConfigOverride() { // Flip the state of the cache context. The block label should now be // overridden. - \Drupal::state()->set('config_override_integration_test.enabled', 'yes'); + \Drupal::state()->set('config_override_integration_test.enabled', TRUE); $this->drupalGet(''); $this->assertText('Overridden block label'); diff --git a/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php b/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php index 23e228b..d8e87e9 100644 --- a/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php +++ b/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php @@ -28,7 +28,7 @@ public static function getLabel() { */ public function getContext() { // Default to the 'disabled' state. - $state = \Drupal::state()->get('config_override_integration_test.enabled', 'no'); + $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE) ? 'yes' : 'no'; return 'config_override_integration_test.' . $state; } diff --git a/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php b/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php index c4956df..c04089f 100644 --- a/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php +++ b/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php @@ -23,8 +23,8 @@ public function loadOverrides($names) { $overrides = []; // Override the test block depending on the state set in the test. - $state = \Drupal::state()->get('config_override_integration_test.enabled', 'no'); - if (in_array('block.block.config_override_test', $names) && $state !== 'no') { + $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE); + if (in_array('block.block.config_override_test', $names) && $state !== FALSE) { $overrides = $overrides + [ 'block.block.config_override_test' => [ 'settings' => ['label' => 'Overridden block label'],