Problem/Motivation
Onmultilingual sites, nodes created with language 'not specified' appear on the Content page in the default language instead of the user interface language.
I added a simple patch, but I'm not sure about consequences outside the described use-case.
The $entity->toURL() method adds the entities current language as an URL option to the link generator. The provided patch applies the current language as a prefix base if the nodes language is "not specified".
Steps to reproduce
- Install Umami. This uses URL negotiation and configure path prefixes
- Create new node using "not specified" as language
- Go to es/admin/content
What behavior were you expecting?
The main link to the entity inside the content table should link to /es/node/N (the current user interface language based on the url es/admin/content).
What happened instead?
The main link to the entity inside the content table links to /node/N, which changes the site language (based on language path prefix) back to english.
Proposed resolution
Update the language negotiation URL plugin to ensure that if language is not defined for the current content, adopt the default language from the URL.
Remaining tasks
Review
User interface changes
N/A
No visible UI changes, as content links will be pointing to the current language.
API changes
N/A
Data model changes
N/A
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #60 | interdiff.txt | 1.49 KB | lauriii |
| #60 | 2883450-60.patch | 2.46 KB | lauriii |
| #52 | interdiff-2883450-51-52.txt | 1.13 KB | mohit_aghera |
| #52 | 2883450-52.patch | 2.26 KB | mohit_aghera |
| #45 | 2883450 Notspecied.png | 183.05 KB | aarti zikre |
Issue fork drupal-2883450
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Patrick Bauer commentedComment #3
Patrick Bauer commentedComment #4
cilefen commentedComment #6
andypostAny reason to change url language to url one if it was defined already?
Comment #7
Patrick Bauer commentedI don't really understand your question, could you elaborate? My code change should only fire if the content is language neutral.
Comment #8
Patrick Bauer commentedHad the wrong paths in my first patch. Updated to new paths.
Comment #9
Patrick Bauer commentedComment #11
Patrick Bauer commentedFixed patch format.
Comment #12
TBI commentedBelow are the following steps:
1. Install Content Translation module.
2. Add the Language in Configuration -> Regional and language -> Languages.
3. Click on the Detection and Selection tab next to the List tab on the languages page
4. Enable the Browser detection method and save the settings.
5. Select Enable Translation and Show language selector on create and edit pages under Language settings on edit page of content type.
6. Add translated content for the node on click the Translate option under operations for the node.
7. After add the content, on change the site in another language when click on node title it goes to node detail page with prefix url of that language.
Comment #13
Patrick Bauer commentedThats right, but that doesn't work for nodes which are not translated but instead are language neutral (Language = not-specified).
We have content thats not translated, but valid for every language thats available on the page.
Comment #14
TBI commentedThe patch in #11 is working perfect. If we choose "-not-specified" option in Language field while creating node. On change the language of the site. The node opens with that language prefix.
Comment #15
dinesh18 commentedIt seems when we select (Language = not-specified), it will take the default path prefix code which is English in your case.
I don't think we really require a patch for (Language = not-specified). If suppose there are more than 2 languages then what should be the path prefix ?
Comment #16
Patrick Bauer commentedYou're right, it uses the default path prefix (english in this case). But if I'm an italian user and click on a teaser for a language neutral content, I will automatically be redirected to the english interface language version of the site. The current implementation forbids to ever view language neutral content with a non-default language user interface.
Like the patch and my issue description states: use the path prefix of the currently used language. A german user will get /de/node/123, an italian user /it/node/123 and the english user will get /node/123. That way the content can be viewed while still using the users interface language.
Comment #18
svdhout commented@Patrick Bauer Good catch
I can confirm that the patch in #11 fixes the problem with language neutral content being linked to without path prefix.
The patch doesn't do anything when the language is set to not applicable, so the same buggy behaviour occurs.
This issue causes a lot of other problems with links to language neutral entities, such as media items etc:
https://www.drupal.org/node/2670144
https://www.drupal.org/project/drupal/issues/2798977
https://www.drupal.org/project/drupal/issues/2645922
https://www.drupal.org/project/drupal/issues/2889892
https://www.drupal.org/project/drupal/issues/2798977
I think this is a way better solution then adding the language inside each formatter.
I'll point the other tickets to this one, so it can be tested further.
Comment #19
Patrick Bauer commentedThank you, please do!
Do you think there may be more edge cases which could make problems? Adding "not applicable" to the exceptions would be a simple addition.
Comment #21
borisson_We'll probably need to add tests for this.
Comment #22
borisson_I tried writing a test to fix this, but I can't find a good way to do this. I'm not sure what test-class or module this should go in. Should this be in a new test?
Comment #24
gngn commented#11 fixes the problem for me
Comment #25
blacksnipeFix in #11 works here too.
Thanks Patrick.
Comment #26
gngn commentedSo what do we do about "not applicable"?
Wouldb be something like
but I am not sure if we need it.
Comment #28
nuezComment #29
nuezComment #31
enrocean167 commentedThe attached patch adds support for content with language set to not applicable.
Comment #32
philkay commentedFix provided in #11 works for me on Drupal 8.8.1
Comment #33
vdsh commentedFix in #31 worked for me (however, probably not linked to this patch, but I realized that the url was not taking the alias defined by pathauto, so I had to resort to hook_preprocess_node to rewrite the URL).
Comment #34
semiaddict commentedThank you @patrick-bauer and @corneboele.
Patch #31 is working great for me.
Comment #38
madhu_h commentedVerified and tested the Merge request !
https://www.drupal.org/files/issues/2019-12-09/drupal-language-prefix-ne...
Testing Steps:
* Install a new Drupal instance
* Add an additional language (e.g. italian)
* Use URL negotiation and configure path prefixes (e.g. /en for english and /it for italian)
* Enable the language selector for content type
* Create new node using "not specified" as language
* Go to /it/admin/content
* The main link to the entity inside the content table should link to /it/node/1 (the current user interface language based on the url /it/admin/content).
Test Results:
Verified that after applying patch language neutral content is taking appropriate URL aliases on switching languages
Refer SS
https://www.drupal.org/files/issues/2021-09-28/Screenshot%202021-09-28%2...
https://www.drupal.org/files/issues/2021-09-28/Screenshot%202021-09-28%2...
Can be moved to RTBC
Test Status: PASS
Comment #40
anybodyConfirming #31 works fine and fixes the issue on Drupal 9.3.x! So RTBC+1 but still needs tests.
Setting the priority to major as this is broken "basic" functionality. The sibling issue, which I first thought was the cause: https://www.drupal.org/project/drupal/issues/2862511 is also set to major.
Where to put the tests? And which tests are expected here?
Comment #41
vistree commentedI tested #31 with current 9.3.9 - and it works as expected!!
Comment #43
quietone commentedI have read the IS and skimmed the issue. I tried to test on Drupal 10, standard install, and found that the steps to reproduce was missing an item to enable translation on content. There are also points in #16 that should be in the Issue Summary. Adding tag for an Issue Summary update. See Write an issue summary for an existing issue for guidance.
Updating the Issue Summary on this issue is a suitable first time issue, adding novice tag.
Comment #44
akashkumar07 commentedRerolled the patch #31 for 10.0.x-dev.
Comment #45
aarti zikre commentedVerified and tested the patch provided by #44 for 10.x dev version.
https://www.drupal.org/files/issues/2022-06-10/2883450-44.patch
Tested both the cases "Not Specified" and "Not Applicable"
Testing Steps For Not specified:
Testing Steps For Not Applicable:
Screen Shorts:
Before


After
After Applying #44 patch for not specified content
After Applying #44 patch for not applicable content
After Applying #44 patch not selecting any language in URL prefix (shows default language)
Test Results:
Verified that after applying patch language neutral content is taking appropriate URL aliases on switching languages
FYI #31 and #44 both the patches are same.
Can be moved to RTBC
Test Status: PASS
Comment #46
catchThis could still use some automated test coverage, moving to needs work for that.
Comment #47
reenaraghavan commentedComment #48
reenaraghavan commentedComment #49
quietone commented#2670144: Node title links to default language when language not specified was a bugsmash triage target today. I have closed it as a duplicate of this one. I have updated the Issue Summary on the suggestion made by mstrelan in Slack.
Comment #50
quietone commentedComment #51
mohit_aghera commentedAdding test cases and test-only patches.
Comment #52
mohit_aghera commentedOops, fixing phpcs issues and queuing again for bot.
Comment #54
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Confirmed the issue in D10
Standard install
Enabled a 2nd language (german in my case)
Allow for content translation of basic page content type
Create a node selecting "not specified"
URL is node/1
Go to de/admin/content
URL of NodeA is /node/1
Applied patch
cleared cache
URL of NoadeA is de/node/1
Moving to NW for the issue summary update that was requested in #43
Comment #55
mohit_aghera commentedThanks for the review @smustgrave
I've tried to attempt issue summary update. Can you please have a look at it once.
Keeping the issue tag for now, feel free to remove it after verification.
Comment #56
mohit_aghera commentedComment #57
smustgrave commentedThanks! @mohit_aghera
Comment #59
mohit_aghera commentedLooks like random failures related to CKEditor5.
Triggering for re-test and moving it to RTBC again.
Comment #60
lauriiiMade some minor changes to the test case.
Comment #62
lauriiiCommitted 6f24730 and pushed to 10.1.x. Thanks!
Comment #64
drupalfan2 commentedThank you.
Patch #60 seems to work in Drupal 9.
Comment #65
duneblI confirm #60 apply for D9.5
Comment #66
kala4ekThat issue was breaks links that must be always neutral, like links inside sitemap.xml (if there are a lot of links the additional sitemaps are generated) and most probalby some more such cases.

Because the code was relied on "not applicable" language, but now the language applied anyway...
Comment #67
arnalyse commentedWe're running into an issue similar to the one kala4ek described.
The OpenID Connect module generated its redirect URIs like https://default/openid-connect/generic, but now includes the language, e.g. https://default/en/openid-connect/generic
This is a huge problem for us, as it breaks the SSO login for our users when upgrading to D10.1
An issue for this hals already been created: https://www.drupal.org/project/openid_connect/issues/3383036
The OpenID Connect module generates its links as follows:
I'm not sure that
LANGCODE_NOT_APPLICABLEshould get a language as the definition ofLANGCODE_NOT_APPLICABLEreads as follows:I'd like to help resolve this, so if anyone knows what the correct way to generate a url without a langcode should be from now on, please let me know, so I can generate a patch for the OpenID Connect module.
Comment #68
anybodyThanks for the reports. Still I think it was correct to *fix* this and I think this is a new side-effect and issue we have to discuss. Perhaps in a separate issue linking this one to understand the history?
Just an idea: Perhaps the right way would be to also provide a language neutral URL for such contents?
And eventually need a flag to determine which kind of link we need?
I think we can clearly see we can have both cases... this is a really complicated and very general task. Needs heavy discussion, I think.
Comment #69
sboden commentedIn my mind it's clear that the current fix for LANG_CODE_NOT_APPLICABLE is wrong.
In the case of LANG_CODE_NOT_APPLICABLE no language prefix should be generated. No language prefix was generated before, it should not after since it will break a lot of stuff around the world. If you use LANG_CODE_NOT_APPLICABLE, you specifically don't want langcode, why would langcode be added?
See also https://www.drupal.org/project/drupal/issues/3385550, I spent an hour trying to figure out why openid_connect breaks. I will include a patch in the latter issue.
Comment #70
anybody@sboden not really sure it's a safe thing, but if it is, we need a follow up which doesn't only implement that but also adds proper documentation to inform users about the important differences (propably below the selection), I think that's the most important difference then.
But let's wait for core maintainers feedback here, I think?
Comment #71
sboden commentedSo what I see as a "problem" is for following code (it's a small piece from an openid_connect library):
Assume you don't know anything about the APIs being called and you just see this piece of code.
Do you expect "/nl" (in my case) to be added to the URL or not? That's the question and the problem I'm having. In the code above I set language explicitly to "not applicable" so I expect the "/nl" language prefix will not be added.
It did not add a language prefix before the fix, but it does now.
I also have no other easy way to get rid of the language prefix (unless we make a LANGCODE_ABSOLUTELY_NOT_APPLICABLE case, just kidding... don't do it). In my case above the generated URL is used for openid_connect and the "other side" just can't handle a language prefix.