Problem/Motivation

On a multilingual site, the same path alias cannot be set for two different languages.

Steps to reproduce

  1. Enable the Language module
  2. Add the English and Japanese languages to the site
  3. Set the URL prefix to /en for English and /jp for Japanese (in /en/admin/config/regional/language/detection/url )
  4. Allow the language to be changed for the Basic page content type (tick the "Show language selector on create and edit pages" checkbox in the "Language settings tab" in /en/admin/structure/types/manage/page )
  5. On /en/node/add/page set the language to English, put /demo as path alias; and save
  6. On /en/node/add/page set the language to Japanese, set /demo as path alias, and save
  7. The alias /demo is already in use in this language will appear as error message

Notice the "...in this language" part of the error message (although you have selected a different language when saving the second page).

CommentFileSizeAuthor
#52 interdiff_48-52.txt1.65 KBmurilohp
#52 3179599-52.patch3.07 KBmurilohp
#51 3179599-51.patch2.78 KBNikhil_110
#51 interdiff_48-51.txt711 bytesNikhil_110
#48 3179599-48.patch2.47 KBmurilohp
#48 interdiff_42-48.txt1.33 KBmurilohp
#48 3179599-48-test-only.patch1.47 KBmurilohp
#42 interdiff_37-42.txt883 bytesmurilohp
#42 3179599-alias-issue-fixed-42.patch1022 bytesmurilohp
#37 3179599-alias-issue-fixed_11.patch1014 bytesTharunkumar Nunna
#36 3179599-alias-issue-fixed_10.patch1015 bytesTharunkumar Nunna
#32 3179599-alias-issue-fixed_9.patch1.55 KBTharunkumar Nunna
#31 3179599-alias-issue-fixed_8.patch1.6 KBTharunkumar Nunna
#30 3179599-alias-issue-fixed_7.patch1.56 KBTharunkumar Nunna
#29 3179599-alias-issue-fixed_6.patch1.56 KBTharunkumar Nunna
#26 3179599-alias-issue-fixed_5.patch1.51 KBTharunkumar Nunna
#23 3179599-alias-issue-fixed_4.patch1.51 KBTharunkumar Nunna
#22 3179599-alias-issue-fixed_3.patch1.51 KBTharunkumar Nunna
#21 3179599-alias-issue-fixed_2.patch1.51 KBTharunkumar Nunna
#20 3179599-alias-issue-fixed_1.patch1.55 KBTharunkumar Nunna
#19 3179599-alias-issue-fixed.patch1.55 KBTharunkumar Nunna
#16 path_alias.patch655 bytesTharunkumar Nunna
#14 interdiff_12-14.txt1.15 KBvsujeetkumar
#14 3179599_14.patch1.76 KBvsujeetkumar
#12 interdiff_10-12.txt986 bytesvsujeetkumar
#12 3179599_12.patch1.32 KBvsujeetkumar
#10 3179599_10.patch1.31 KBvsujeetkumar
#7 The-alias-is-already-in-use-in-this-language-3179599.patch1.31 KBshivam kaushal
#4 3179599-4.patch2.1 KBkishor_kolekar
#3 interdiff-2_3.txt907 bytesOscaner
#3 3179599-3.patch2.13 KBOscaner
#2 3179599-2.patch2.11 KBOscaner

Issue fork drupal-3179599

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Kang Miao created an issue. See original summary.

Oscaner’s picture

FileSize
2.11 KB
Oscaner’s picture

Status: Active » Needs work
FileSize
2.13 KB
907 bytes
kishor_kolekar’s picture

Status: Needs work » Needs review
FileSize
2.1 KB

Status: Needs review » Needs work

The last submitted patch, 4: 3179599-4.patch, failed testing. View results

shivam kaushal’s picture

Assigned: Unassigned » shivam kaushal
shivam kaushal’s picture

Assigned: shivam kaushal » Unassigned
Status: Needs work » Needs review
FileSize
1.31 KB

Status: Needs review » Needs work

The last submitted patch, 7: The-alias-is-already-in-use-in-this-language-3179599.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Lendude’s picture

Version: 8.8.x-dev » 9.1.x-dev
Issue tags: -language-content, -path, -url alias +Needs tests, +Bug Smash Initiative

Thanks for reporting and thanks for working on this.

Moving this to the Drupal core version that is currently receiving bug fixes.

We will need an automated test to demonstrate this issue occurs in a clean Drupal install and the fix needs work because it is currently failing a fair number of tests.

vsujeetkumar’s picture

Re-roll patch for 9.1.x.

vsujeetkumar’s picture

Status: Needs work » Needs review
vsujeetkumar’s picture

Fixed the phpcs issue.

Status: Needs review » Needs work

The last submitted patch, 12: 3179599_12.patch, failed testing. View results

vsujeetkumar’s picture

Status: Needs work » Needs review
FileSize
1.76 KB
1.15 KB

Fixing fail tests.

Status: Needs review » Needs work

The last submitted patch, 14: 3179599_14.patch, failed testing. View results

Tharunkumar Nunna’s picture

The following patch file is working fine for me

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

command related issues are fixed

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

changes are modified to support both 8.9 and 9

The last submitted patch, 3179599-alias-issue-fixed_3.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 3179599-alias-issue-fixed_4.patch, failed testing. View results

Tharunkumar Nunna’s picture

apaderno’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: 3179599-alias-issue-fixed_5.patch, failed testing. View results

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

apaderno’s picture

Title: The alias is already in use in this language. » The same path alias cannot be set for two languages
Issue summary: View changes
apaderno’s picture

+    $langcode_ = $form_values['langcode'][0]['value'];

We don't use variable names ending with an underscore.

+    if ($aliasStatus == 'node') {
+      $langcode = $element['langcode']['#value'];
+    }

$aliasStatus isn't a self-descriptive name. Is really necessary to check if the path alias is for a node? The same issue would be present whether the path alias is for a different entity.

-        'langcode' => $element['langcode']['#value'],
+        'langcode' => $langcode,
+        // 'langcode' => $element['langcode']['#value'],

There is no need to show the previous code as commented line.

Tharunkumar Nunna’s picture

Drupal 7:

User have a choice to create multi-language pages in any content type.

Ex : en/demo.html - 'Article' content-type and jp/demo.html in 'Basic page' content-type - its possible and it works

Drupal 8 and 9 :

User don't have a choice and should must create multi-language pages in same content-type of source language.

Ex : /en/demo.html - 'Article' content-type and /jp/demo.html in 'Basic page' content-type - its not possible

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

Tharunkumar Nunna’s picture

Status: Needs work » Needs review

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

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should 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.

parisek’s picture

Version: 9.3.x-dev » 9.4.x-dev
joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php
@@ -83,7 +83,12 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+    $otherAlias = \Drupal::service('path_alias.manager')->getPathByAlias($alias, $form_values['langcode'][0]['value']);

Local variable names should be in camel case.

Also the service should be injected.

Also, as noted already, needs a test.

murilohp’s picture

Hey @joachim thanks for the review!

  1. Local variable names should be in camel case. Done! Changed the variable to be snake_case
  2. Also the service should be injected. Regarding this point, are you sure we should inject the service in this scenario? The function validateFormElement is static
  3. This still needs a test, so I'll leave this as NW.
joachim’s picture

> The function validateFormElement is static

Oh, whoops. You're right, it can't be injected into a static!

Thanks for the fix!

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.

klonos’s picture

Issue summary: View changes

Updating issue summary with some details and slightly reordering steps to what makes sense.

Tharunkumar Nunna’s picture

Priority: Normal » Major
Status: Needs work » Needs review
murilohp’s picture

Thanks for IS update @klonos, with that information I was able to create a test and replicate the bug. Here's a new patch, and a test-only patch.

The last submitted patch, 48: 3179599-48-test-only.patch, failed testing. View results

jonathanshaw’s picture

Status: Needs review » Needs work

Nice work @murilohp

+++ b/core/modules/path/tests/src/Functional/PathLanguageTest.php
@@ -212,4 +212,32 @@ public function testAliasTranslation() {
+    $this->assertSession()->pageTextContains('Basic page ' . $edit['title[0][value]'] . ' has been created.');

I don't really like this as a way of verifying the outcome here. I'd prefer to see something that proves more explicitly that we really have 2 nodes with the correct different paths.

Otherwise RTBC.

Nikhil_110’s picture

Re-roll patch #48 and apply changes #50

murilohp’s picture

Status: Needs work » Needs review
FileSize
3.07 KB
1.65 KB

Hey! Thanks for the review @jonathanshaw! I've updated the test, now, the test will test,validate the page and also asserts the path alias.

@Nikhil_110, thanks for the patch, but I didn't get what you've done, you basically changed an unrelated test, so this new patch is based on #48.

joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php
@@ -83,7 +83,12 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+    $other_alias = \Drupal::service('path_alias.manager')->getPathByAlias($alias, $form_values['langcode'][0]['value']);

This could do with a comment to explain what it's doing.

Currently it looks like it's part of the 'Trim...' code.

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.