Problem/Motivation
In issue #540294: Move node language settings from Locale to Node module, the language settings were moved from locale.module to node.module. An apparently accidental change occurred at the same time, where new nodes that are created on a single-language site are now always the site default language, instead of LANGUAGE_NONE.
This causes some new issues when dealing with URL aliases on a single-language site. URL aliases that are created manually do not have the option to set a language, so therefor langcode is always "und" in the url_alias table for manual aliases. However, all nodes that are created are the default language, and so you end up in a situation where one alias is used for the actual path, and another alias is shown on the node form. Changing the alias in the node form no longer affects the actual URL at all any more, because the manual alias (created after the node) always wins.
The reason for this behavior is because the url_alias table, in the database, will contain two aliases pointing at the same node. One is for "und", and the other is for "en". The latest alias in the table (regardless of langcode) will be the alias used in the URL. While the langcode that matches the node will be used in the node form.
All of this is due to a shift in the way nodes are created by default on a single language site:
- Drupal 7: All nodes are LANGUAGE_NONE in a single-language site.
- Drupal 8 and later versions: All nodes are the default language in a single-language site.
It seems that the change in Drupal 8 did not intend to introduce an inconsistency between the node form and standalone URL alias form.
Even on a multilingual site, the standalone URL alias form defaults to 'not specified':

Steps to reproduce
- Install latest version of Drupal 11 using the standard profile.
- Navigate to /admin/content and create a new Basic page node. Set the path alias to "about".
- Navigate to /admin/config/search/path and add a new URL alias with the system path "node/1", and the path alias "about2".
- Navigate to "node/1". Note that the URL alias is now "about2".
- Edit the node. The URL alias on the node form is still "about", not "about2". Any changes you make to the path alias at this point will have no effect at all, the path alias will always be "about2".
Proposed resolution
Make it so that all aliases created on a single-language site use the default language instead of LanguageInterface::LANGCODE_NOT_SPECIFIED. Multilingual sites could respect the content language settings that can be configured at /admin/config/regional/content-language - this would include defaulting to the site default language.
Remaining tasks
Create merge request. Apply patch to the MR.
User interface changes
None.
API changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | 2484411-39-interdiff.txt | 929 bytes | lokapujya |
| #39 | 2484411-39.patch | 5 KB | lokapujya |
| #38 | 2484411-38.patch | 3.5 KB | lokapujya |
| #15 | manual_path_aliases_are-2484411-15.patch | 734 bytes | mirom |
| #18 | TEST_ONLY-manual_path_aliases_are-2484411-18.patch | 1.01 KB | strykaizer |
Issue fork drupal-2484411
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 #1
quicksketchI'm also not sure that the bugs created by this change are major or critical, but I do believe that it should be decided ASAP if this behavior of assuming the default language on a single-language site is intentional. So perhaps "major" is suitable at least until we decide if the behavior of new nodes should be changed.
Comment #2
quicksketchMatching issue over in GitHub for Backdrop: https://github.com/backdrop/backdrop-issues/issues/903
Comment #3
plachI'm pretty sure the current behavior is by design, so I guess we need to fix URL alias handling. Assigning to Gabor to get some direction.
Comment #4
gábor hojtsyI think the current behavior in terms of node language is by design. While users may need to review their nodes when they go multilingual, the 80% use case is you are usually creating content in the site default language and not in unknown. In fact with the current situation, its much more likely that you don't need to modify existing content when going multilingual, or only need to modify little as opposed to most with the Drupal 7 behavior. To filter down to nodes created before going multilingual you can also use a date filter, which is much more accurate compared to filtering by language, which would include nodes created after the change.
Comment #5
gábor hojtsy@quicksketch: as for criticality as per https://www.drupal.org/core/issue-priority data-loss bugs are critical, but here there is too much data rather than loosing data. Retitled for the actual bug vs. what made the bug happen.
BTW while that would not solve the problem per say, I would argue that the manual UI should allow for specifying language for the alias, it is supposed to be a fully capable UI to edit aliases.
Comment #6
googletorp commentedWhat is the expected behavior if you create a language neutral alias for a path that has a language specific alias. I would think that the language specific always would win, and only function as a fallback.
Comment #7
quicksketchCool, yeah the change just didn't seem intentional. The new behavior may or may not make more sense, it's difficult to really evaluate. However, if we want the default language to be applied to new content, this behavior should probably be applied to Taxonomy terms and nodes created via the API (right now it's the node form specifically that sets this behavior).
However, the bug at hand is probably mostly around URL aliases, and adding a language selector even on a mono-lingual site would solve some of the problem.
Comment #8
quicksketchOn a further note, inconsistency is also a problem when dealing with some aliases that should be undefined language and some that should be the default language. For example if Taxonomy terms are not set to the default language on mono-lingual sites, then you'll end up in a situation where manually-defined aliases in the default language may not show up in the Taxonomy term form, as the form is going to try and load the same language alias as the entity language. The entity language and the alias language must be the same.
From the sound of Gábor's suggestion, the following may be appropriate:
- All entities that support language should default to the current site default language, not undefined, at the API level rather than in just the node form.
- URL aliases (at least for entities) should also always default to the current site default language. So that when editing an entity the latest alias is always shown in the entity form, creating consistency between the URL used and the alias in the form.
Or as a completely different approach, perhaps the only thing that needs to be done is allowing mono-lingual sites to load undefined language aliases on the entity form, even if the entity is the default language. That sort of mixing could get messy.
Comment #9
gábor hojtsyThese were supposed to be resolved by #1966436: Default *content* entity languages are not set for entities created with the API last year. If that is not how it works then test coverage added there was insufficient(?). BTW that issue also showcases how intentional the behavior is. There are 252 comments over a year and a half on there.
The alias widget in general should load/save the alias in the language of the (node) form. That would allow to load/save/edit aliases for translations also transparently.
Comment #10
quicksketchI'm probably mistaken then, I didn't look into it too deeply past the initial patches that were made years ago.
Yep, this is the case. I meant aliases that are created under
admin/config/search/pathshould probably default to the current site language, so that the widget on the node form can load the manually created alias. Right now the difference in languages causes the odd behavior.It sounds like the only thing that needs to be done here to solve the bug is to make site aliases use the default language on monolingual sites, though it seems likely that would have side-effects.
Comment #11
gábor hojtsyI agree the admin/config/search/path form should default to the site default language for path aliases when a language selector is not present, same as entities. Its sad that path aliases are this non-entity non-config things, we need to reimplement behaviors for them that apply to everything else. :/
Comment #12
gábor hojtsyUnfortunately nobody is working on this, so removing from sprint.
Comment #13
catchMarked #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) as duplicate.
Comment #14
mirom commentedComment #15
mirom commentedComment #16
gábor hojtsyThe patch implements
, looks good. For multilingual sites, path alias UI has a language selector and defaulting to site default there also makes sense.
Does need tests.
Comment #17
gábor hojtsy@catch: not sure it is an upgrade path issue on a multilingual site at least. On a monolingual site, we can update all existing path aliases (need an update function for that), but on multilingual sites, we cannot really be sure if a path was explicitly set to no language or implicitly.
Comment #18
strykaizerAttached you'll find a test only and a test + patch from #15
Comment #20
stefan.r commentedComment #21
stefan.r commentedRan this manually and this looks good:
Just wondering if the language might not be set to English for another reason? Maybe we could do the test with another default language as well, just to be sure?
Comment #22
gábor hojtsyYeah this at least proves we are setting a language now :) Another test (few more lines AFAIS) with another language would be nice.
Comment #23
gábor hojtsyComment #24
stefan.r commentedComment #25
stefan.r commentedHmm is #24 actually still testing what is in the IS? It adds a new language so is this still a single-language site? :/
Comment #26
gábor hojtsyI think this looks fine. It fixes the situation described in the issue summary as well as adding more tests.
Comment #27
gábor hojtsyComment #28
webchick#13/#17 talk about an upgrade path, but I don't see one here. Do we need it or?
Comment #29
gábor hojtsyYeah as I said we can do an upgrade path for und => en on sites without language module. On sites with language module, we don't really know the language of the paths, they may or may not be for the current default language and they or may not be intentionally und.
Comment #30
Anonymous (not verified) commentedBack to NW for #29.
Comment #31
swentel commentedComment #32
gábor hojtsyTo be very safe, I would only update aliases where the langcode was und. If the site had multiple languages before and is currently monolingual, then there is no significant data loss at least.
Or check if the unique langcodes is a single language (and optionally und). That is, the site was always monolingual at most, and only do the update then.
Again for such cases when there is data for aliases from a prior state of the site as multilingual.
Also we need tests for upgrade paths :/
Comment #34
gábor hojtsyRemoving from sprint so it reflects what is currently being worked on. Unfortunately.
Comment #36
catchDowngrading this after a discussion with @xjm @effulgentsia @alexpott @plach @swentel @berdir @amateescu
There are two parts to this bug:
1. The language defaults on the path alias admin UI - we decided this is just a normal bug.
2. Those aliases not showing up on the node form, I've re-opened #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) to be just about that bit.
The patch here addresses #1. We also discussed leaving the upgrade path here, since there's a risk of data-loss from it, and #2 mitigates a bit.
Comment #37
catchComment #38
lokapujyaReroll for 8.1.
Comment #39
lokapujyaNeeds tests for the upgrade path. Got something started.
Comment #42
berdirBased on the call that we had, it is my understanding that we will not have an update function, so we also don't need a test for it :)
Instead of fixing the data (only for single-language sites, impossible to do for multilingual), we'd fix the node form in #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) to support existing aliases with UND.
Just because we change the default here doesn't mean that it is impossible to create such aliases. It is in fact perfectly valid to do so and we have to support that scenario properly.
Comment #44
berdirWe might be able to close this as a duplicate of #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) and #2689459: If you don't want to translate your URL alias, the original URL alias won't work with your translations.
Comment #45
pwolanin commentedrelated? #2065977: drupal_lookup_path shows wrong url
Comment #47
bloomt commentedSo when I select none as the language for the url alias it allows me to use the alias for the translated path. For example /test and /es/test go to the same page when language none is selected. Is there a way to set the path language to none by default?
Comment #49
5hawn commentedThis is my use case as well. Is there a patch for this?
Comment #52
gagarine commentedCan we commit the patch without an upgrade path?
Comment #54
bkosborneI ran into this today as well as I was developing code to prevent content managers from adding multiple aliases for the same system path. I was very confused by the behavior that aliases created on node forms are given the "en" language while aliases created on the alias form are given the "und" language, and have no option to select anything else.
I agree the path forward to fix this is that for monolingual sites, the form for manually adding an alias should behave the same way that the nod form does.
Comment #55
gagarine commentedNobody cares about the stable version.
Comment #56
xjm@gagarine The release managers care. :P
Bugfixes should be filed against the bugfix branch unless fixing them is disruptive. Since this one requires an upgrade path, though, we usually make those changes minor-only, so I'm moving it to 9.1.x. Thanks!
Comment #63
james.williamsGoing by catch's update in #2484411-36: Manual path aliases are not the same as aliases on the node form, I've updated the issue summary to say this issue is now just about fixing the the language defaults on the path alias admin UI. Together with Berdir's comment #2484411-42: Manual path aliases are not the same as aliases on the node form, it sounds like the decision was made that an upgrade path is no longer necessary. There was also mention in other comments (e.g. #11) about defaulting the language selector to use the default language on multilingual sites, which isn't strictly within the scope of the current issue title, but sounds very relevant to me so I've included it in my issue summary update.
The most recent patch still includes the upgrade path, but is also very old - I'd be amazed if it still applies! But in the meantime, #3449408: Use interface language on the add URL alias form contains an mergeable MR which I believe is a solution for this anyway. It's tests need some work, maybe we can bring across updated tests from here to there, or the work from there to here?
Comment #64
ironnuts commented@james.williams Looking at patch #39 here there is some useful looking test code usable in the test for #3449408: Use interface language on the add URL alias form
Comment #68
xjmSaving credits from @catch's issue triage comment in #36.
Comment #70
ironnuts commentedComment #71
ironnuts commentedComment #72
ironnuts commentedComment #73
ironnuts commented