- π¬π§United Kingdom longwave UK
Found this following π Enable service autoconfiguration for core event subscribers Fixed
If we enable autoconfiguration, that means we can automatically add the
cache.context
tag to services that implement a specific interface. But as I found over there, not all cache contexts actually implement CacheContextInterface. - last update
over 1 year ago 29,367 pass - π«π·France andypost
I think we should start throw deprecation if cache contexts does not implement context interface
+++ b/core/tests/Drupal/KernelTests/Core/Cache/CacheCollectorTest.php @@ -60,4 +62,15 @@ public function providerTestInvalidCharacters() { + * Tests that cache contexts implement the right interfaces. ... + public function testContextImplementsInterface() { + $cache_contexts = \Drupal::service('service_container')->findTaggedServiceIds('cache.context'); + foreach (array_keys($cache_contexts) as $context) { + $service = \Drupal::service($context); + $this->assertTrue($service instanceof CalculatedCacheContextInterface || $service instanceof CacheContextInterface);
This test still makes sense but needs to throw deprecation if collector discovers cache context without interface
- π«π·France andypost
+++ b/core/lib/Drupal/Core/Cache/Context/RequestStackCacheContextBase.php @@ -11,7 +12,7 @@ -abstract class RequestStackCacheContextBase { +abstract class RequestStackCacheContextBase implements CacheContextInterface {
The change in #18 is BC break so collector should care about it
Looking at usage of
CalculatedCacheContextInterface
there's only one check for interface in\Drupal\Core\Cache\Context\CacheContextsManager::getLabels()