Hi,
when "Content" language negotiation is enabled the links in the interface language switcher are broken, in particular they never allow to change the interface language (see also #2860901: Doubts about Content language negotiation).
Look at the images below:
This is because LanguageNegotiationContentEntity::processOutbound()
unsets $options['language']
and this means that the current url language prefix would be forced in the generated links, as stated in Url::fromUri under "Parameters", array $options, 'language'.
A way to fix this could be to mark in some way that the URLs come from another language switcher, and in that case leave them alone.
A "proof of concept" patch is on its way.
Thanks,
Antonio
Comments
Comment #2
ao2 CreditAttribution: ao2 as a volunteer commentedI am attaching a patch which fixes the problem by marking the interface language switcher URLs in
LanguageNegotiationUrl::getLanguageSwitchLinks()
, so thatLanguageNegotiationContentEntity::processOutbound()
knows that they are to be left alone.It is a hack, if you will, and it is meant only as a base for a discussion about how to fix the problem properly.
This is the end result, which I think is what the final solution should be targeting:
Comment #3
ao2 CreditAttribution: ao2 as a volunteer commentedExplain better where the doc about
Url::fromUri
is.Comment #4
ao2 CreditAttribution: ao2 as a volunteer commentedHere's an update, changes since the patch in #2 (see also the interdiff):
Comment #7
marcoscanoNot sure about the best approach either, but I have:
- confirmed the bug exists
- confirmed that the patch solves the issue
- rerolled the patch
- wrote a test for that
Comment #9
ao2 CreditAttribution: ao2 as a volunteer commented@marcoscano, thanks for re-rolling and adding a test.
BTW have you also taken a look at #2863465: LanguageNegotiationContentEntity: make links to entities only change the content language by any chance?
Ciao,
Antonio
Comment #13
vredko CreditAttribution: vredko as a volunteer and commentedThanks @marcoscano for the patch. i've updated it for 8.9.x
Comment #14
james.williams CreditAttribution: james.williams at ComputerMinds commentedRe-rolled to apply to 9.3.x
Comment #18
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.