diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index 556926d..e88560e 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -65,7 +65,7 @@ * * @var int */ - protected $cacheMaxAge; + protected $cacheMaxAge = Cache::PERMANENT; /** * The maximum length of a configuration object name. @@ -298,14 +298,14 @@ public function getCacheContexts() { * {@inheritdoc} */ public function getCacheTags() { - return ['config:' . $this->name]; + return Cache::mergeTags(['config:' . $this->name], $this->cacheTags); } /** * {@inheritdoc} */ public function getCacheMaxAge() { - return Cache::PERMANENT; + return $this->cacheMaxAge; } /** diff --git a/core/modules/config/src/Tests/CacheContextConfigOverrideTest.php b/core/modules/config/src/Tests/CacheContextConfigOverrideTest.php index 00ce58b..38cbb42 100644 --- a/core/modules/config/src/Tests/CacheContextConfigOverrideTest.php +++ b/core/modules/config/src/Tests/CacheContextConfigOverrideTest.php @@ -7,6 +7,7 @@ namespace Drupal\config\Tests; +use Drupal\Core\Cache\Cache; use Drupal\simpletest\KernelTestBase; /** @@ -23,15 +24,19 @@ class CacheContextConfigOverrideTest extends KernelTestBase { public function testConfigOverride() { // It's pirate day today! - $GLOBALS['arr_me_mateys'] = TRUE; + $GLOBALS['it_is_pirate_day'] = TRUE; $config_factory = $this->container->get('config.factory'); $config = $config_factory->get('system.theme'); - $theme = $config->get('default'); + // Check that we are using the Pirate theme. + $theme = $config->get('default'); $this->assertEqual('pirate', $theme); - $this->assertEquals(['pirate_day'], $config->getCacheContexts); + // Check that the cacheable properties are correct. + $this->assertEqual(['pirate_day'], $config->getCacheContexts()); + $this->assertEqual(['config:system.theme'], $config->getCacheTags()); + $this->assertEqual(Cache::PERMANENT, $config->getCacheMaxAge()); } } diff --git a/core/modules/config/tests/config_override_test/config_override_test.services.yml b/core/modules/config/tests/config_override_test/config_override_test.services.yml index 88f3550..886b7fd 100644 --- a/core/modules/config/tests/config_override_test/config_override_test.services.yml +++ b/core/modules/config/tests/config_override_test/config_override_test.services.yml @@ -1,4 +1,8 @@ services: + cache_context.pirate_day: + class: Drupal\config_override_test\Cache\PirateDayCacheContext + tags: + - { name: cache.context } config_override_test.overrider: class: Drupal\config_override_test\ConfigOverrider tags: diff --git a/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php b/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php new file mode 100644 index 0000000..44c344f --- /dev/null +++ b/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php @@ -0,0 +1,47 @@ + ['default' => 'pirate']]; } @@ -55,8 +56,6 @@ public function getCacheContexts() { * {@inheritdoc} */ public function getCacheTags() { - // @todo This is here because we now implement CacheableDependencyInterface, - // but this is not used. return []; } @@ -64,8 +63,6 @@ public function getCacheTags() { * {@inheritdoc} */ public function getCacheMaxAge() { - // @todo This is here because we now implement CacheableDependencyInterface, - // but this is not used. return Cache::PERMANENT; }