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':
Screenshot showing that the Language element on the add URL alias form has no specified language selected

Steps to reproduce

  1. Install latest version of Drupal 11 using the standard profile.
  2. Navigate to /admin/content and create a new Basic page node. Set the path alias to "about".
  3. Navigate to /admin/config/search/path and add a new URL alias with the system path "node/1", and the path alias "about2".
  4. Navigate to "node/1". Note that the URL alias is now "about2".
  5. 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

Issue fork drupal-2484411

Command icon 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

quicksketch’s picture

Priority: Normal » Major

I'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.

quicksketch’s picture

Matching issue over in GitHub for Backdrop: https://github.com/backdrop/backdrop-issues/issues/903

plach’s picture

Assigned: Unassigned » gábor hojtsy
Issue tags: -multilingual +D8MI, +language-content, +sprint, +Needs technical direction

I'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.

gábor hojtsy’s picture

I 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.

gábor hojtsy’s picture

Title: Single-language sites now set $node->langcode to site default language instead of LANGUAGE_NONE » Manual path aliases are not the same as aliases on the node form on single-language sites
Assigned: gábor hojtsy » Unassigned
Issue tags: -Needs technical direction

@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.

googletorp’s picture

What 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.

quicksketch’s picture

I 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.

Cool, 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.

quicksketch’s picture

On 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.

gábor hojtsy’s picture

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). [....] 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.

These 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.

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.

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.

quicksketch’s picture

These 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(?).

I'm probably mistaken then, I didn't look into it too deeply past the initial patches that were made years ago.

The alias widget in general should load/save the alias in the language of the (node) form.

Yep, this is the case. I meant aliases that are created under admin/config/search/path should 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.

gábor hojtsy’s picture

I 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. :/

gábor hojtsy’s picture

Issue tags: -sprint

Unfortunately nobody is working on this, so removing from sprint.

catch’s picture

mirom’s picture

Assigned: Unassigned » mirom
Issue tags: +Drupalaton 2015
mirom’s picture

Status: Active » Needs review
StatusFileSize
new734 bytes
gábor hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

The patch implements

Make it so that all aliases created on a single-language site use the default language instead of LanguageInterface::LANGCODE_NOT_SPECIFIED.

, looks good. For multilingual sites, path alias UI has a language selector and defaulting to site default there also makes sense.

Does need tests.

gábor hojtsy’s picture

@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.

strykaizer’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests +DUGBE0609
StatusFileSize
new1.01 KB
new1.72 KB

Attached you'll find a test only and a test + patch from #15

The last submitted patch, 18: TEST_ONLY-manual_path_aliases_are-2484411-18.patch, failed testing.

stefan.r’s picture

Assigned: mirom » Unassigned
stefan.r’s picture

Issue summary: View changes
StatusFileSize
new35.17 KB

Ran 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?

gábor hojtsy’s picture

Yeah this at least proves we are setting a language now :) Another test (few more lines AFAIS) with another language would be nice.

gábor hojtsy’s picture

Status: Needs review » Needs work
stefan.r’s picture

Status: Needs work » Needs review
StatusFileSize
new2.52 KB
new3.49 KB
stefan.r’s picture

Hmm is #24 actually still testing what is in the IS? It adds a new language so is this still a single-language site? :/

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

I think this looks fine. It fixes the situation described in the issue summary as well as adding more tests.

gábor hojtsy’s picture

Issue tags: +sprint
webchick’s picture

Status: Reviewed & tested by the community » Needs review

#13/#17 talk about an upgrade path, but I don't see one here. Do we need it or?

gábor hojtsy’s picture

Yeah 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.

Anonymous’s picture

Status: Needs review » Needs work

Back to NW for #29.

swentel’s picture

Status: Needs work » Needs review
StatusFileSize
new4.16 KB
new599 bytes
gábor hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
+++ b/core/modules/path/path.install
@@ -0,0 +1,17 @@
+      ->fields(array('langcode' => \Drupal::service('language.default')->get()->getId()))

To 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 :/

The last submitted patch, 31: 2484411-31.patch, failed testing.

gábor hojtsy’s picture

Issue tags: -sprint

Removing from sprint so it reflects what is currently being worked on. Unfortunately.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

catch’s picture

Priority: Major » Normal

Downgrading 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.

catch’s picture

Issue tags: -D8 upgrade path
lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new3.5 KB

Reroll for 8.1.

lokapujya’s picture

StatusFileSize
new5 KB
new929 bytes

Needs tests for the upgrade path. Got something started.

The last submitted patch, 38: 2484411-38.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 39: 2484411-39.patch, failed testing.

berdir’s picture

Based 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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pwolanin’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

bloomt’s picture

So 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?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

5hawn’s picture

So 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?

This is my use case as well. Is there a patch for this?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gagarine’s picture

Version: 8.6.x-dev » 8.8.x-dev

Can we commit the patch without an upgrade path?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bkosborne’s picture

I 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.

gagarine’s picture

Version: 8.9.x-dev » 9.0.x-dev

Nobody cares about the stable version.

xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev

@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!

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

james.williams’s picture

Title: Manual path aliases are not the same as aliases on the node form on single-language sites » Manual path aliases are not the same as aliases on the node form
Component: node system » path.module
Issue summary: View changes

Going 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?

ironnuts’s picture

@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

xjm credited alexpott.

xjm credited amateescu.

xjm credited effulgentsia.

xjm’s picture

Saving credits from @catch's issue triage comment in #36.

meeni_dhobale made their first commit to this issue’s fork.

ironnuts’s picture

Issue summary: View changes
ironnuts’s picture

Issue summary: View changes
ironnuts’s picture

Issue summary: View changes
ironnuts’s picture

Issue summary: View changes

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.