Follow-up to #2354889: Make block context faster by removing onBlock event and replace it with loading from a ContextManager
Problem/Motivation
There's a core service language manager that could be swapped and #2354889: Make block context faster by removing onBlock event and replace it with loading from a ContextManager added ContextProvidersPass
that searches for tagged services context_provider
but no definition found.
But core is multilingual without language module, so we always have language manager with 3 default language types!
The bug here is inaccessibility of current language context without language module because "current language context" lives not in core.
That's why we have useless compiler pass...
The only difference that \Drupal\language\ConfigurableLanguageManager::getLanguageTypes
provides this types from config.
Proposed resolution
Move service implementation from language module to core.services.yml
Remaining tasks
Reviews
Commit
Update CR https://www.drupal.org/node/2527840
User interface changes
None
API changes
CurrentLanguageContext
class moved
from Drupal\language\ContextProvider
to Drupal\Core\Language\ContextProvider
namespace
with service definition from language module to core.services.yml
Data model changes
None
BETA EVAL:
- - Issue priority: Bug, because current language is meaningful without language.module
- - Priorized changes: Follow-up to a very recent critical.
- - Disruption: None, the critical just moved that context from block module to language module and the context name is unchanged.
Comment | File | Size | Author |
---|---|---|---|
current_language_context.patch | 1.97 KB | andypost | |
Comments
Comment #1
andypostUpdated IS
Comment #2
jibran+1 to the change.
This makes it at least major bug. I let @Gábor Hojtsy RTBC it cuz we might need tests for this.
Comment #3
BerdirDrupal is lingual without language.module but hardly multi unless someone writes an alternative implementation of language.module.
This is fine as long as we don't change the service ID because that's part of the data structure now.
Comment #4
Gábor HojtsyIt is technically true that Drupal is multilingual by default because the default languages Not specified and Not applicable are present even without language module (additionally to the default language). See LanguageManager::getDefaultLockedLanguages().
I think the move is fine. Do we have existing tests to ensure this works?
Comment #5
andypost@Gabor
CurrentLanguageContext::getRuntimeContexts()
intersects passed IDs with Language Types, not the the languages!Comment #6
Berdir@Gabor: Fine, you win :) But those languages are never the current language. Content can have that language but getCurrentLanguage($type) will never return them ( I hope, that would be scary.. ;))
Comment #7
Gábor Hojtsy@anydpost: yeah I reacted on "But core is multilingual without language module". The language types themselves do not guarantee multilingual behavior, and those will never select any other language but the site default unless some custom language module replacement is used. I can see that for that use case, this patch is helpful. That is a pretty edge case though as it seems.
Anyway, where is existing test coverage for this one? So we made sure tests are fine. :)
Comment #8
andypostThe only kernel test I see is checking runtime language context when language override is used.
That's a tricky, yep, but better do that after commit of parent issue then later.
Comment #9
andypostupgrade path is not affected
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI think we should be fine here. RTBC - Current language should not change even with new language module implementations.
Comment #11
xjmThanks everyone. Couple questions about the beta evaluation:
How is renamespacing a class and moving a service definition "no disruption"?
What is the impact on code that used or extended the old class? What is the impact on an existing site that uses the service? We should evaluate whether we need a CR or upgrade path here, even if we think the BC break is warranted.
Comment #12
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#11: In this case the service is named the same, hence no disruption.
Given that the upgrade path has not even been finished, yet for the issue and this was just moved by a critical issue, there is indeed zero disruption.
We could not even write an upgrade path if we wanted to, the only thing we could do if we really wanted to keep BC is to leave a class in language.module, subclass the other class and not register it as a service, so that someone hypothetical could still subclass it from language module.
However chances of some actually subclassing that are really slim ...
Lets add a quick CR though ...
Comment #13
BerdirAdding a CR for this is a lot of noise for nothing IMHO. Instead, lets make sure the original issue is updated and lists the renamed services and their (final) class name.
Comment #14
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#13: Yes, sounds good.
Comment #15
xjmAlright, thanks.
So were the class and service only just added in #2354889: Make block context faster by removing onBlock event and replace it with loading from a ContextManager? If so let's at least document that in the beta eval here. :) Wasn't clear to me.
Comment #16
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #17
dawehnerWell these are also examples for those classes which could be marked as final, as they are the end of any inheritance chain. When you would like to change the behaviour of one of them, there is no reason why you not just exchange the service and be done.
In other words, I don't see a usecase in extending those classes in contrib.
Comment #18
Berdir@dawehner: Not convinced by that at all. If you're going to replace the node route context service for example, it's quite likely that you want to extend.. there's very likely no reason at all to duplicate the getAvailableContexts() method, you would just extend getRuntimeContexts().
Comment #19
dawehnerWhy would you want to extend such a tiny little class?
Comment #20
alexpottCommitted c78f1da and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.
Let's update the CRs.
Comment #22
andypostThanx, CR updated https://www.drupal.org/node/2527840/revisions/view/8652794/8710096