Updated: Comment #16
Problem/Motivation
The original poster, Dave Cohen, reported this problem running D6:
I get Page not Found errors with pathauto when locale is enabled. The aliases get associated with "English" and never work. If I manually edit an alias, changing it to "All languages", then it works. Not sure whether this is bug or my configuration, would appreciate help either way.
The problem was simplified (the Pathauto module is not required) and reproduced in D7 and D8. The configuration quirks in the original poster's site do not seem to be relevant.
Steps to reproduce (from #11 and #13)
Using Drupal core 7.21 and Pathauto 7.x-dev: Elaborating on the steps to reproduce in D7 and D8 (based on the thread above):
- Configure Drupal:
- D7: enable the core Locale and Content Translation modules.
- D8: enable the core Language and Content Translation modules
- D7/D8: visit admin/config/regional/language, press "Add language" and select "Spanish" from the drop-down
- D7/D8: press the "Detection and Selection" tab aka as admin/config/regional/language/configure
- D7/D8 In the column of tick boxes make sure that Detection Method URL is unticked while Detection Method Session is ticked; leave the remaining tickboxes set to what they are
- Configure Content Types:
- D7: on the content type settings page for Article admin/structure/types/manage/article tick the Publishing options tab and then the Enabled radio button under "Multilingual support."
- D8: visit /admin/config/regional/content-language and tick the Content box (Custom Language Settings) as well as the Article box in the Translatable column.
- D7/D8: add content: node/add/article, specify an alias under "URL path settings" and in the Language drop-down select "English". Save
- D7/D8: Verify that you can View the page via the URL alias
- D7/D8: Edit the page, changing the language selector to Spanish. Save.
- You can now no longer View the page via its URL alias, although node/... still works.
Is this the problem or a feature?? It's a problem, at the very least it s counterintitutive and not clearly documented…
Proposed resolution
In #8 SiliconMind proposed an explanation of the problem:
I think that this happens because drupal_lookup_path from path.inc uses global $language_url variable to get current language. But the problem is that $language_url is set to default language if language was not set via url. This is wrong because language could be selected through user preferences or browser language.
The real problem is that url alias should work always regardless of selected language!
Workaround for this is to alter drupal_lookup_path queries to search url_alias table for entries that match provided alias but not necessarily match language that is provided by $language_url variable. The goal is to always return alias source if it exists regardless of selected language.
Remaining tasks
Issue Summary update
Move the patch in #95 to a separate issue.
Manual testing
- Finish charactarizing the problem and determine if we have one issue or several.
- Decide what the desired behavior is.
- Create a patch.
- Design tests.
- Update documentation
- Backport to D7.
User interface changes
(New or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text.)
There will clearly be some…
Once this is sorted out it would be very good to document the behavior and make it easily accessible from the language configuration pages.
Another nice change would be to include the language of a page in the content listing on multi-lingual sites (although this should probably be a separate issue).
API changes
At the moment there do not appear to be any.
Original report by Dave Cohen
Rather than "hijack" #320710: Pathauto URL Alias leading to Page Not Found, submitting new issue. I find I get Page not Found errors with pathauto when locale is enabled. The aliases get associated with "English" and never work. If I manually edit an alias, changing it to "All languages", then it works. Not sure whether this is bug or my configuration, would appreciate help either way. More about the problem: Drupal is unilaterally modifying paths specified by the content author, without notifying the content author.
Proposed resolution
- Do not modify user-supplied paths.
- If it's absolutely necessary to modify user-supplied paths, at least inform the user.
- Avoid 404'ing user-supplied paths -- make them redirect to the changed path, maybe?
Beta phase evaluation
| Issue category | Bug because it is a functional error in the system preventing valid use cases |
|---|---|
| Issue priority | Major because significant repercussions, impacting many people (at least 3 other issues for this have been opened, possibly more). |
| Comment | File | Size | Author |
|---|---|---|---|
| #104 | 1125428-language-specific-aliases-only-work-with-url-based-language-negotiation-d11.2.0-rc2.patch | 3.69 KB | andrelzgava |
| #95 | 1125428-95.patch | 3.77 KB | yash.rode |
| #93 | 1125428-93.patch | 2.85 KB | yash.rode |
| #78 | 1125428-alt-78.patch | 5.66 KB | alexpott |
| #78 | 77-78-interdiff.txt | 6 KB | alexpott |
Comments
Comment #1
dave reidSo I'm guessing that you're browsing the site in a non-English language when this is happening? Also please confirm the correct version of Pathauto you are using - 6.x-1.2 is fairly old.
Comment #2
Dave Cohen commentedSorry I submitted this to pathauto when it's not even an automatically generated alias.
May not be a bug in drupal, as something is odd about my installation. Even after uninstalling the locale module, I still see a "Language" column (with nothing in it) when I edit path aliases. Weird.
Comment #3
nitvirus commentedMaybe the locale module is not completely uninstalled.Happened with me (on a module i dont remember) i forgot to uncheck it from the list of modules and deleted it
Comment #4
Dave Cohen commentedI believe it has something to do with the "language_default" variable, which is left around after locale module uninstalled. I deleted that and I think things are working, but I can't say 100% if that was the difference.
Comment #5
cmcintosh commentedI am having a similar issue, it seems that when Locale is enabled, but a node type is not enabled for translation, then i get this error. If i enable it for translation and set the nodes for neutral the error seems to go away, I have not tested it with a set language as of yet.
Comment #6
cmcintosh commentedOkay setting a node to anything but Language Neutral causes issues.
Comment #7
giorgio79 commentedI am also experiencing this in D7.
It seems only for content types I created after enabling locale.
Here is a proposed solution #1534600: URL Alias leading to Page Not Found on multilingual site
Comment #8
siliconmind commented#1534600: URL Alias leading to Page Not Found on multilingual site is not a solution. That's a workaround you'd have to repeat each time after creating new content. The issue still remains. Alias that has language set to something different than "any" or site default does not work and leads to "page not found".
This is not related to pathauto module. If you create alias manually the behaviour is the same.
Comment #9
siliconmind commentedI think that this happens because drupal_lookup_path from path.inc uses global $language_url variable to get current language. But the problem is that $language_url is set to default language if language was not set via url. This is wrong because language could be selected through user preferences or browser language.
The real problem is that url alias should work always regardless of selected language!
Workaround for this is to alter drupal_lookup_path queries to search url_alias table for entries that match provided alias but not necessarily match language that is provided by $language_url variable. The goal is to always return alias source if it exists regardless of selected language.
Comment #10
catch@SiliconMind would you be able to provide either steps to reproduce from a clean core install or even better an extension to the existing path alias tests which demonstrates this?
Comment #11
siliconmind commentedSteps to reproduce:
Comment #12
dcam commentedhttp://drupal.org/node/1427826 contains instructions for updating the issue summary with the summary template.
The summary may need to be updated with information from comments.
Comment #13
rdeboerProblem/Motivation
Elaborating on the steps to reproduce in D7 and D8 (based on the thread above):
o D7: enable the core Locale and Content Translation modules; D8: enable the core Language and Content Translation modules
o D7/D8: visit admin/config/regional/language, press "Add language" and select "Spanish" from the drop-down
o D7/D8: press the "Detection and Selection" tab aka as admin/config/regional/language/configure
o D7/D8 In the column of tick boxes make sure that Detection Method URL is UNticked while Detection Method Session is TICKED; leave the remaining tickboxes set to what they are
o D7: on the content type settings page for Article admin/structure/types/manage/article tick the Publishing options tab and then the Enabled radio button under "Multilingual support"; D8: visit /admin/config/regional/content-language and tick the Content box (Custom Language Settings) as well as the Article box in the Translatable column.
o D7/D8 add content: node/add/article, specify an alias under "URL path settings" and in the Language drop-down select "English". Save
o D7/D8: Verify that you can View the page via the URL alias
o D7/D8 Edit the page, changing the language selector to Spanish. Save.
You can now no longer View the page via its URL alias, although node/... still works.
Is this the problem or a feature??
Proposed resolution
(Description of the proposed solution, the rationale behind it, and workarounds for people who cannot use the patch.)
Remaining tasks
(reviews needed, tests to be written or run, documentation to be written, etc.)
User interface changes
(New or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text.)
API changes
(API changes/additions that would affect module, install profile, and theme developers, including examples of before/after code if appropriate.)
Related Issues
(A list of related issues.)
Original report by [username]
(Text of the original report, for legacy issues whose initial post was not the issue summary. Use rarely.)
Comment #14
ge commentedUsing the steps in #13 in a clean install of D8, after publishing the initial English article:
Stay logged in and go to the article, you get a Translations tab
Within the Translations panel you get a listing of translations
English is shown as having the translation {title of article} and the status "Published"
Spanish is shown as having the translation "n/a" and status "Not translated"
The path of the original article is /path-set-by-author
After changing the language to Spanish:
English is shown as having the translation {title of article} and the status "Not published"
Spanish is shown as having the translation {title of article} and the status "Published"
The path of the article republished in Spanish is /es/path-set-by-author
The original path of the original article /path-set-by-author is now 404.
Screen shots attached.
Comment #15
rdeboer@ge, #14: "The original path of the original article /path-set-by-author is now 404."
Sorry am new to I18n and stuff.... so is the above observation indeed the bug? Or is this how we want it to operate?
If it is a bug, then it is a bug in both D7 and D8 and we should update the title to something more descriptive.
Comment #16
ge commentedAgreed, I am likewise unsure whether the problem lies in the path getting changed or the content author not being notified of the change. The effect is that the original article at the original path appears to the content author to get silently de-published so it goes 404. Added this info to the issue summary so someone with more knowledge on this point can evaluate the appropriate direction to go.
Comment #16.0
ge commentedAdd detail and (success criteria for) proposed resolution
Comment #16.1
dlu commentedStarting work on an issue summary.
Comment #16.2
dlu commentedMerging comments into Issue Summary.
Comment #16.3
dlu commentedTesting links
Comment #16.4
dlu commentedSaving a version.
Comment #16.5
dlu commentedUpdated issue summary.
Comment #16.6
dlu commentedUpdated issue summary.
Comment #16.7
dlu commentedUpdated issue summary.
Comment #16.8
dlu commentedUpdated issue summary.
Comment #16.9
dlu commentedUpdated links.
Comment #17
noomz commentedThis is just an implementation to correct the URL looking-up.
Comment #18
jhedstromdrupal_lookup_path()was removed, and the underlying logic substantially refactored in #1269742: Make path lookup code into a pluggable class. Is this an issue in 8.x anymore at all? If not, it should be bumped back to 7.x.Comment #19
baisongNotes from triage with @metzlerd
Comment #20
mitokens commentedRelated issues links moved to sidebar.
Comment #21
xjm(Saving proposed issue credit for discussion and triage participants at LA.)
Comment #25
shaalWorking on this as part of #FLDC17
Confirming that the bug still exists on Drupal 8.4.x-dev clean install, and can be reproduced by following the steps that are written in the summary.
Needs an initial patch to fix this bug.
Comment #26
keopxHi @shaal
I can't reproduce in 8.2.6. Do you what is the change? Can you explain steps to reproduce it?
Thanks
Comment #27
danepowell commentedWe're seeing a variation of this behavior on Drupal 8.2.6 that I'm pretty sure is caused by this bug.
Basically, on a site with multiple translations, repeatedly editing and saving a translated node with path aliases defined causes the aliases to be sporadically lost.
* Set path aliases to be translatable
* Create a translation for a node
* Add a path alias if it doesn't exist and save the page
* Note that node translation is correctly aliased in the URL
* Edit node again and save without making any changes
* Path alias has mysteriously vanished
Setting the path aliases to not be translated results in an even worse bug, the path doesn't take effect at all in that case. Possibly due to #2689459: If you don't want to translate your URL alias, the original URL alias won't work with your translations
Comment #28
cilefen commentedI discussed this issue with @xjm, @cottser, @catch, @alexpott and @lauriii. We agreed this should be increased to critical priority because data is disappearing.
(edited)
Comment #29
cilefen commentedSorry, we agreed this is actually critical.
Comment #30
catchI just read the steps in the issue summary, and they looked like a duplicate of #2689459: If you don't want to translate your URL alias, the original URL alias won't work with your translations at first, but they're not:
The result after I followed the steps was I had a Danish node, and a record in the URL alias table like this:
That looks fine to me, exactly as expected.
The URL alias is rendered correctly on admin/content, but I get a 404 when trying to visit it. The alias table is fine, so this could be an issue with the incoming path processor or session language negotiation, but it's not data loss.
I wasn't able to reproduce the issue with the steps in #27 at all. That means I'm pretty sure this is closer to #2802403: Combination of language negotiation and path aliasing can cause a corrupted route cache, 404s than a data issue/form/translation issue.
Comment #31
catchComment #33
a.milkovskyWhat if we detect the language in the path alias processor?
See the patch.
Comment #35
a.milkovskyofcourse tests failed, because the constructor is now different. I can fix tests, but please verify the approach first.
Comment #36
berdirThe tests fail because the constructor is wrong, not just different. You need to type hint on the interface, not on the actual class. I'd suggest try that and then we'll see how much test fails are remaining.
Comment #37
a.milkovskyFixed the interface type hint.
Comment #40
berdir@a.milkovsky: I don't think your change makes a difference. \Drupal\Core\Path\AliasManager::getPathByAlias() already falls back to the current language() if none is explicitly provided.
I've been debugging this as well, and the fix that is working for me is adding the language to the RouteProvider cache.
The easiest way to reproduce this is a site with per-language domains, given example.de and example.fr, where only the de site has a working alias/page on "/path".
When you visit example.fr/path first you get a 404, when you then visit example.de/path you also get a 404 even though it exists, because we have a cache hit on \Drupal\Core\Routing\RouteProvider::getRouteCollectionForRequest() as the path and query arguments are identical.
In a way even more interesting is that if you do example.de/path first (which works) and then visit example.fr/path then that resolves too. So if those were supposed to be different pages, then you might end up with a completely weird page ;)
Also, there have been tons of different problems been mixed up here already, whatever was the inital report in D6/D7 has nothing to do with this specific problem that I'm seeing.
Will try to add some tests, while not possible for multi-domain (at least not as web test), maybe we can do this with user/session negotiation.
Comment #42
berdirThis should fix those fails.
Comment #43
berdirOk, so here is a test, but I actually had to kind of add a workaround for the poblem described here to be able to test my bugfix, so I think my issues is related but not really the same.
I tried to write a test that uses session negotiation to reproduce my problem, but it didn't happen by default. Turns out that was because the language_url negotiation is fixed to language-url. Only by manually setting that to also use session negotiation I was able to reproduce my specific problem of it being cached incorrectly.
I now also see the difference between #37 and HEAD, the patch there uses the language_interface type and by-passes the fallback in AliasStorage. But if that's the conclusion then we should IMHO just change the AliasManager to do that too, which leads to:
The big question here is what exactly is the use case/reason for the language_url to even exist. Right now it simply doesn't make sense if the negotiation doesn't match between content/url, because the user is creating aliases for *content* and expects those to match the URL alias language.
Anyway, for now, here is a test that is failing/passing with my fix.
I suspect my fix is more related to #2802403: Combination of language negotiation and path aliasing can cause a corrupted route cache, 404s (the two issues are closed related anyway)
Comment #45
dawehnerI think this a good change, and we really understand that this is needed. There was some other issue talking about adding generic cache context support, but I think for now this is the right minimal change.
Should we add a comment, why we need to have the language vary by langcode?
Comment #46
berdirOk, I moved my patch over to #2802403: Combination of language negotiation and path aliasing can cause a corrupted route cache, 404s. So back to the drawing board here.
As far as I see, the only "problem" here is that url language type is by default hardcoded to URL negotiation (path or domain) and does not consider session, which is kind of implied by its name.
The bigger question is what exactly the point of the url language type is and I'm honestly unsure. Discussed a bit with @plach and he said "IIRC the idea is that you may want to have a language for UI or content different from the one carried by the current URL". But I don't understand what a real-world use case for that would be to be honest. And @plach could also not come up with a specific scenario but it was also pretty late in the night for both of us :)
The reality IMHO is that the url language *is* the content language. While that is not the case with the default fallback, it is in a lot of places where we explicitly specify the language of a URL. For example on /admin/content, that will always use the translation language of the node for the link. And in this scenario, with only session negotiation, that will lead to a 404.
*But* there is no data loss, the aliases are there. The explanation about changing language on the node is I think only related to the fact that the this then results in an alias that is not in the default language. It doesn't matter if it's set initially or changed later. There are aliases, they're simply not considered because the url language is never $non-default-langcode.
Considering that, I think the current issue title is misleading, my suggestion would be "Language-specific aliases only work with url-based language negotiation".
This issue existed in some form since 2011, that's IMHO another indication that it simply can't be *that* critical ;)
Therefore I would suggest that this is changed back to major issue.
That all said, thinking about a possible solution...
a) We add language-content as a fallback negotiation to the language_url type. So that if url is not enabled at all, it falls back to the content language. We discussed that a bit last night. *But*, any link that explicitly uses the content/entity language when generating a URL (and I think toUrl() on an entity should actually do that by default) will still result in a broken URL because it will result in a link that uses the alias but does *not* have a prefix.
b) If we completely deprecate language_url and stop using it then we still have a problem. The alias will now work, but admin/content shows me the original (in my currently active language) as just /original-alias and the translation as /spanish-alias. The /spanish-alias will now still be a 404 because the link doesn't know that it should be in loaded with the spanish language. for session negotiation, that could be fixed by adding ?language=es to the URL, but that would change your persisted language configuration. And for a language preference stored in your user, you can't even do that on a link. Thinking about this, I suspect this was one of the reasons why we have the language_url language type although we can see that it doesn't really solve the problem because using any non-url based language negotiation method in reality means that there is no way to view an page/entity in a different language.
c) cry and give up...
d) Remove all non-url based language language negotiation methods ;)
e) What actually might work but I haven't fully thought it through yet is when interface and content have different negotiations and you allow something like session or user preference based negotiation only for interface language but content must use path/domain. Then you can have the website in a fixed language, but you're able to view and edit content in any language you want. But that still means that it would be enough to have interface and content language types. It also means that only very few language negotiation configurations really make sense and work. But our current UI allows about a million different variations but most of them actually just allow you to misconfigure it and break some cases. Maybe we should reconsider that generic UI and just offer a few specific options that actually *work*? With a way to override it maybe, in case someone wants to do something stupi... different :)
Comment #47
sjuvonen commented"The bigger question is what exactly the point of the url language type is and I'm honestly unsure. Discussed a bit with @plach and he said "IIRC the idea is that you may want to have a language for UI or content different from the one carried by the current URL". But I don't understand what a real-world use case for that would be to be honest. And @plach could also not come up with a specific scenario but it was also pretty late in the night for both of us :)"
The most common use-case for overriding content language setting is dead simple: moderators/editors/admins want to be able to moderate ALL CONTENT under a single domain, because separate domains require separate login sessions and Drupal has no OOB support for sharing sessions between multiple domains. User sessions are a problem when language negotiation is done at the domain level.
I think the issue is becoming more critical now that Drupal is considered to have multi-language support OOB and not every module has to be hacked in one way or another to provide support. People are less afraid to use it and more prone to running into problems with it.
Comment #49
StepanISK commentedThe patch does not work for me.
As I understand
/core/core.services.yml patch is not needed
/core/lib/Drupal/Core/Routing/RouteProvider.php partially
/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php need
/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php not needed
Comment #50
maticb commentedI had a similar issue in Drupal 7 + pathauto, and I found out the problem was with the missing language prepend.
I tried patching core and went with the idea from #17, but all it resulted in was an endless loop of redirects.
Ended up fixing with a hack-ish thing, that simply forces all content to have a language prepend:
I am posting this as I work on the issue, so this might have a glaring flaw that I haven't found yet.
Also keep in mind these could be specific to my setup.
Comment #52
manuel.adanAs mentioned at #2666628-11: Language-aware aliases are broken with anything but path language negotiation, a workaround to this:
Comment #54
jibranNow that path alias is an entity can we quickly add test to make sure this is still an issue? Is #43 test only patch correct interpretation of the bug?
Comment #55
avpadernoComment #56
catchMoving this back to major. This is really a problem with us allowing people to configure a site such that it doesn't work as expected, the individual pieces are working as they should.
IMO session language negotiation is the bug and we should just deprecate it, then remove it entirely, although #817114: Deprecate the session language detection method was marked won't fix nine and a half years ago.
Marking #1294946: Language detection based on session doesn't work with URL aliases as duplicate.
Comment #57
gregori.goossens commentedHi,
just for information, i needed to apply steps describe in #52 for resolve problem with translated aliases.
I use a custom language negotiation based on proxy vars due to a complex multi-language proxy configuration (that can't work with default url / domain negotiation).
So, in my case, it really matters to be able to edit configuration for LanguageInterface::TYPE_URL.
Thanks,
Comment #58
gregori.goossens commented@manuel.adan
Be aware,
like mention above, i use #52 instruction to configure my custom language negotiation for generate good alias (for example in language switcher). But, when in enable a new module (or disable) system reset url language negotiation to ->url.
Did you experience such problem ?
Thanks.
Comment #60
kunalkursija commentedI checked it on 3 different sites with Drupal versions mentioned below, And the issue still exists:
Steps in #13 mentioned this being the problem with language detection method of
session, But I think its beyond that and is rather true of other language detection methods as well.Assumption: The default site language is English.
Steps to reproduce:
language&content_translationmodulesadmin/config/regional/language. AddSpanish&Frenchlanguages./admin/config/regional/language/detectionand ensure your language detection and selection methods for Interface text language detection and Content language detection are set toURL. [I don't this step matters and the issue exists for other detection and selection methods too. I have mentioned this step as I tested the whole thing with this config. See attached screenshot for the config.]Englishand add URL aliasSpanishsuch that it also has alias. [This step is optional]Change the language of English node to French. Without doing anything to URL alias, Save the node.Summary: Changing the language of source translation is causing the node to loose its URL alias.
Comment #62
manuel.adanAn update on #52 in response to #58, the locked flag must be removed from the URL language type to prevent the settings being reset on module (un)installation.
Instead of patching core with #2824086-9: URL language detection has missing title and description, the URL language type can be altered in a hook_language_type_info_alter() implementation as follows:
/** * Implements hook_language_type_info_alter(). */ function MY_CUSTOM_MODULE_language_types_info_alter(array &$language_types) { // Make URL language negotiation configurable by removing the 'locked' // flag. Work-around until #1125428 // #2824086 // #2666628 from core // solved. $language_types[LanguageInterface::TYPE_URL]['locked'] = FALSE; unset($language_types[LanguageInterface::TYPE_URL]['fixed']); // Set name and description, not provided by core since this is considered // as internal. $language_types[LanguageInterface::TYPE_URL]['name'] = t('URL'); $language_types[LanguageInterface::TYPE_URL]['description'] = t('Order of language detection methods for URLs. If a language prefix is configured for the detected language, it will be added to the URL.'); }Comment #65
daniel.bosenI ran into a similar situation today, but with user negotiation instead of session.
Steps to reproduce:
standardprofilelanguagemodule (content_translationis disabled)admin/config/regional/language. Add a language - I used german for testing - and set this language as default.admin/config/regional/language/detectionuntick URL and and selectUserinsteadSave settingsExpected result: The node is accessible with the given alias.
Actual result: You get a "Page not found" on the alias.
The funky thing is, you can fix this, at least for the default language, when you got to the configuration form of the disabled "URL language detection configuration" (
admin/config/regional/language/detection/url) and remove the path prefix of the default language.Now you can actually access the page with the alias. I would have assumed, that the configuration of a disabled language detection should not have any impact.
Comment #66
alexpottHere's the simplest tests to reproduce this bug without changing default languages or doing anything too surprising.
This will create an alias with the language 'de' but the alias does not work and leads to a 404. There is no way for the site to determine a \Drupal\Core\Language\LanguageInterface::TYPE_URL with this set up.
The question is what should we do here? @Berdir's comment in #46 lays out some of the options. I think the key statement is
FWIW this issue get's even worse if you change your default language - see #3262873: "Content monolingual" sites with multiple interface translations are very difficult to set up
Comment #67
alexpottHere's a fix for this issue. It allows the AliasRepository to fallback to any language if the URL negotiation is not enabled because there's no way we can use path aliases to negotiate language in this case - so that feels reasonable. I also explored setting all path alias' langcode to UND when this is the case but that haas the downside of not working as expected if you turn off URL negotiation after creating some content.
Comment #69
alexpottHere's an alternate implementation that ensure new aliases have the UND language when created and url language negotiation is off. I think this fix needs further work to ensure that if URL language negotiation is disabled and the aliases in a language other than the default language or UND we display a warning that they will not work and also on the alias edit form to disable the language selector if the alias is a new alias and URL language negotiation is disabled.
Comment #71
alexpottI think the test fails indicate there are problems with setting the langcode in presave or even in the create hook - because we have stuff that sets the langcode outside. The default value for langcode of path aliases in already UND so I think we have to fix the callers to use the correct default depending on langcode configuration. So we need to fix the PathItem field.
Comment #73
quietone commentedClosed #3020627: Creating a content with another language different from the official site one displays a 404 error using the alias. as a duplicate, adding credit.
The difference with that issue is what is ticked on the detection page,

And I tested the patch in #71 and it did not work for me.
Comment #74
quietone commentedalexpott asked in Slack for me to confirm my results. I retest, starting from a drush D10 standard install. I followed the steps in the IS, except the second language was Italian. And reproduced the bug.
So, the patch does work for new nodes. :-)
Comment #75
alexpott@quietone - ah okay - I see - yep exisiting content is tricky. I came up with a solution that would work for existing content in #67 but this broken some pretty explicit testing of expectations. For example, \Drupal\Tests\path\Functional\PathLanguageTest::testAliasTranslation() has the following code:
Which is almost exactly your steps for existing content.
The reason I went from #67 to #69 is this. If you create aliased content with URL language negotiation on the content is available at
langcode/alias. With #67 it would suddenly be available at/aliaswhich does not feel right.However as @quietone one as pointed out if you then edit the translation and save it the code in #69 doesn't update the alias to have a langcode of UND... essentially you can into a spot where you can never fix the alias on the node edit for so that's not correct.
We could consider updating the path alias langcode to UND if URL negotiation is disabled. I think might be the best fix.
Comment #76
alexpottThis however will result in the following behaviour if you do the following:
Is this the correct behaviour? Not sure.
I think one thing I can say is the current behaviour in HEAD is the worst of all possible choices and #67 represents a big improvement for a site with multiple languages and Detection Method URL disabled. One possible way forward is to delete aliases in languages other than the default or UND if the user disables the URL detection method after warning the user. Or we could disable the ability to disable in this case and tell the user to remove the language specific aliases first.
What do people think?
Comment #77
alexpottSo here's some work on #76. It prevents a user disabling the language URL method when there are aliases not in the default language.
However while working on this I was trying to explain why I was only targeting the interface language type. And I really couldn't explain it because in AliasManager it's always doing LanguageInterface::TYPE_URL - it turns out that \Drupal\language\HttpKernel\PathProcessorLanguage::initProcessors() is what registered language negotiators for path processing and that uses \Drupal\Core\Language\LanguageManagerInterface::getLanguageTypes() which only returns the configurable processors. But is that correct shouldn't we also/only be doing TYPE_URL here? Let's see what falls if we do. If I make this change then multilingual aliases keep working even if you disable language url from language interface detection. However the interface stays in the default language. Which is pretty much what I think should happen. Thoughts...
Comment #78
alexpottHere's the alternate approach with tests fixed... probably need some more explanation.
Comment #82
alexpottThe fails for #78 were randoms caused by JS and the theme blocks stuff.
Comment #84
xjmComment #86
smustgrave commentedTriggering for 10.1
Comment #87
smustgrave commentedTried testing #78
Drupal 10.1 with a standard install
Enabled a 2nd language
Checked "Language from a request/session parameter"
Unchecked "Language from the URL (Path prefix or domain)"
Enabled translations for Articles
Created an Article with alias /english
Edited the Article by changing language to my 2nd language
Save the page and the URL is node/1
Go back into edit and my alias is gone.
Adding it back
I still can't go to /english
Let me know if I tested wrong.
Comment #88
kristen polI just ran into this problem on a Drupal 9 site as follows:
Show language selector on create and edit pagesAdded the patch from #78 and then resaved my Afrikaans node and now it's showing the page as
/af/node79aliasaf. Note that I did have to resave the node... just applying the patch wasn't enough. Do we need an update hook?This doesn't make sense to me because I have path prefix language negotiation disabled. IMO, if that's disabled, it should just allow the alias as is without a path prefix.
That said, I haven't read all the comments above :)
UPDATE: Also tested with "Not specified" and "Not applicable" and the former works without the patch and the later does not (same 404 behavior as non-default-language).
Comment #90
yash.rode commentedTesting on my local and try to fix.
Comment #91
yash.rode commentedI also got the same results as #87
Comment #92
yash.rode commented#88 seems a different problem, if we look at steps to reproduce we want to edit an article and change the language to non-default. In comment #88 we are just creating an article with non default language which is also a bug, but it is not what this issue is talking about.
#3259403: Aliases are lost when entity language is changed from the edit form seems duplicate of this.
I am trying to fix both the Problems in this issue, so we can close the other one.
In my opinion, there are two problems
Comment #93
yash.rode commentedThis should fix both the problems.
Comment #94
yash.rode commentedThe first issue from my comment #92 is not a bug it's designed to work like that, see #347265: URL aliases not working for content not in default language.
Comment #95
yash.rode commentedThis fixes the problem when we try to edit the language of an existing node.
Comment #97
smustgrave commentedComment #98
smustgrave commentedVerified the issue described in the IS.
Ran the tests in #95 without the fix and it correctly failed
Think this is good for committer review.
Comment #99
berdirThe bug fix fixed seems to be very different to what the issue title and summary seem to be talking about? the closed issue #3259403: Aliases are lost when entity language is changed from the edit form seems a better match for that?
Comment #100
yash.rode commentedI agree that the title does not match the fix, but we have already closed #3259403: Aliases are lost when entity language is changed from the edit form, and the issue summary for this is already the same as of the duplicate, so we can just change the title of this issue and continue here?
Comment #101
quietone commentedI am doing triage on the core RTBC queue.
Thanks to everyone for working on this tricky issue.
I read the issue summary. There are steps to reproduce and a proposed resolution, which helps reviewers. However, the proposed resolution refers to drupal_loookup_path which is no longer in core. And it appears the resolution is coming from comment #8, which is 10 years old. The remaining task list has 6 items and there is no indication that they have been resolved. And in the User Interface section there seems to be more tasks. It is rather confusing. Therefor, I am tagging for an issue summary update and setting to needs work.
I read through the comments to determine if there is any task not completed and if the remaining tasks were resolved. There is certainly a lot of discussion here of the problem and possible solutions, all of which should have been summarized in the issue summary. But I fail to see an agreement on the solution. Maybe I missed it? And one patch from here moved to another issue and the latest one is not solving the problem as stated in the Issue Summary.
It was good to find an answer to "what is the use case/reason for the language_url to even exist" (#43). Which is "moderators/editors/admins want to be able to moderate ALL CONTENT under a single domain, because separate domains require separate login sessions and Drupal has no OOB support for sharing sessions between multiple domains. User sessions are a problem when language negotiation is done at the domain level." (#47)
I tested this on Drupal 11.x, using the steps in the Issue Summary. I was able to reproduce the problem. I applied the patch and retested. There was no change. I cleared cache and retested. Again no change. That confirms, for me, that patch #95 is solving the problem in #88 which they say is different. Because this was not tested before setting to RTBC I added the tag for manual testing.
And since the patch in #95 is not fixing the problem in the issue summary, that should be moved to a separate issue. Can someone take care of that?
Comment #102
yash.rode commentedCan we go ahead with #71 and make it work for existing content? I tried testing that the results are same as https://www.drupal.org/project/drupal/issues/1125428#comment-14492542
Comment #103
yash.rode commentedHi, does #78 work for anyone? I went through the issue again and tried all the available solutions, only thing worked for me was #69 but that approach will only work for new nodes. Can someone try #78?
Comment #104
andrelzgava commentedI made it compatible with Drupal 11.2.0-rc2
Comment #107
xjmAdding triage credit per #28: