The same path alias cannot be set for two languages

Created on 29 October 2020, over 3 years ago
Updated 3 March 2023, over 1 year ago

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

🐛 Bug report
Status

Needs work

Version

10.1

Component
Path 

Last updated 6 days ago

  • Maintained by
  • 🇬🇧United Kingdom @catch
Created by

🇨🇳China Oscaner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia klonos 90% Melbourne, Australia - 10% Larissa, Greece

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

  • Status changed to Needs review over 1 year ago
  • 🇧🇷Brazil murilohp

    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.

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom jonathanshaw Stroud, UK

    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.

  • 🇮🇳India Nikhil_110

    Re-roll patch #48 and apply changes #50

  • Status changed to Needs review over 1 year ago
  • 🇧🇷Brazil murilohp

    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.

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom joachim
    +++ 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.

Production build 0.69.0 2024