Problem/Motivation
As discovered in #2802403: Combination of language negotiation and path aliasing can cause a corrupted route cache, 404s the path processors are not working as expected. They are independent of the request that is being processed. Currently this is only visible in case of the alias path processor, which when called in context of X language to process Y language alias will fail:
Given that the current language is EN and we want to process a path /fr/some-alias it will fail and return the alias of path instead
of the path.
Proposed resolution
1. Add the processing request to the request stack and pop it when the processing is done. This would allow all services used during the processing to be specific for the current request. Update the language manger service to return language per request / the current
request from the stack.
2. .. other propositions
Remaining tasks
1. Detect other possible caveats other then the language manager.
User interface changes
None.
API changes
Not sure.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | path-process-2940036-28.patch | 7.29 KB | jonhattan |
| #25 | issue_2940036_25.diff | 817 bytes | jan kellermann |
| #21 | path-process-2940036-21.patch | 4.52 KB | Ankit.Gupta |
| #19 | path-process-2940036-19.patch | 4.51 KB | arunkumark |
| #16 | 2940036-16.patch | 7.22 KB | karishmaamin |
Comments
Comment #2
_Archy_ commentedComment #4
fubhy commentedI just ran across this while working on the GraphQL Module. We are making use of sub-requests to properly resolve contexts from Url objects in our graph. Since our requests all run through /graphql, we have no other option than to use sub-requests to properly set the global contexts used within a variety of internal APIs. The language negotiation, as pointed out by this issue, is one of these and since the request stack is not taken into consideration here, we are always using the negotiated language from the /graphql request which is obviously incorrect.
Comment #5
fubhy commentedWe solved this temporarily by using the
reset()method on the languager manager from within our sub-request.Comment #6
_Archy_ commentedI have created this patch in the parent issue, but I am posting it here as-well. There it was breaking badly, let's see how it performs now.
Comment #15
larowlanAdding some tags
Comment #16
karishmaamin commentedRe-rolled patch against 9.4.x. Please review
Comment #19
arunkumarkRe-rolled the patch to be support for the Drupal 9.5.x
Comment #21
Ankit.Gupta commentedRerolled patch #19 with Drupal 9.5.x
Comment #23
ameymudras commented@ankit the patch #19 already works for Drupal 9.5.x not sure why you re rolled it again, please include a interdiff so that we can verify what are the changes.
@arun the patch #16 contained supporting tests which have been removed from your patch.
Comment #25
jan kellermann commentedWe had a similar problem but this patch is much to invasive. For example all admin-menu-links got wrong language prefix because of missing currentLanguage.
You are right that
AliasPathProcessor::processInbound()does not handle the given request and the given $path is at this point without language prefix:But the called function
getPathByAlias()has an 2nd paramater for language. So you can use:Now you can get the path by alias in other languages than current.
Maybe you will try the patch in combination with your tests.
I did test locally with this code:
If you have trouble with fixed "getCurrentLanguage()" (e.g. for language sensitive access checks) then you have to reset() the languageManager and use the requestStack in this situations. But in general - like in this patch suggested - seems to be too much.
Comment #28
jonhattanTried this to fix #2801397 with no luck. Here's a reroll of the patch in #21 on
mainin case it is of interest to someone. Not changing the status since I was not trying to fix this issue.