Needs work
Project:
Drupal core
Version:
main
Component:
cache system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
12 Aug 2015 at 15:21 UTC
Updated:
8 Oct 2025 at 13:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
borisson_Can't use the
StringTranslationTraitbecausegetLabelis a static method, and those can't use$this->t, aTranslationWrapperis possible though.Attached a patch that does exactly this.
Comment #3
wim leersSounds good.
Also: AAAHHH! Static method, that was the real reason! :) Thanks for pointing that out!
Pinged Gábor Hojtsy for review.
Comment #4
dawehnerMhhhh
This doesn't really match the original usecase of the TranslationWrapper
Comment #5
wim leersThat leaves us with no other options then? Won't fix? Or do you have other ideas?
Comment #6
dawehnerWell, you could do something like this, realize that this issue is not a problem anyway (would you unit test that?) OR convert the method to not be a static method. This is just about admin UIs, so why do we care?
Comment #7
tim.plunkettIf this stays static, we might as well continue calling t().
Comment #8
dawehner@tim.plunkett What would you say if we convert it to a non static method?
Comment #9
tim.plunkettThen we use StringTranslationTrait as usual, no? I don't know why it was static in the first place.
Comment #10
dawehnerWell the idea was to use the label in block UI, but yeah this is not longer possible, so yeah, IMHO we should drop the entire concept of the label, if you ask me. It is even a much smaller BC break than you think it is.
Comment #11
borisson_Attached patch removes getLabel from the
CacheContextInterfaceinterface and getLabels from theCacheContextsManager. It also removes the implementations and fixes the CacheContextsManagerTest (that used the getLabels). I ran phpunit and that passes, let's see if the integration tests need changes.Comment #12
dawehnerIts an API change but I think it is the right one.
We need a beta evaluation to justify that change.
Comment #13
borisson_Changed IS
Comment #14
wim leersThis also means contrib is prevented from building certain advanced modules, which allow you to define or modify the cacheability of things built entirely in the UI.
But that is indeed the only reason.
I personally am +1 for this, we could still add a
LabeledCacheContextInterfacein the future that cache contexts can choose to opt in to.I think we need catch and Fabian's +1s too.
Comment #17
quietone commentedReroll.
Comment #18
dawehnerFrom a BC layer POV maybe keeping this method could be helpful. It could be converted to return an empty array, so existing code doesn't fail.
Comment #19
quietone commentedSince there is ongoing discussion of what the task actually is, removing the novice and php-novice tag.
Comment #21
berdirI would simply add a @deprecated on the interface, so we can remove it in 9.x, there's very little benefit to touch the code to return nothing and then remove it later IMHO.
Comment #32
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #33
borisson_This is still a useful thing to do, we're not using these. However, we now have a deprecation policy that we should follow for this.
\Drupal\Core\Cache\Context\CacheContextsManager::getLabelsshould probably also be deprecated?