It is possible to use the same alias for different nodes in the non-default language

Created on 31 October 2019, over 4 years ago
Updated 20 June 2024, 6 days ago

Problem/Motivation :

Hello,
I didn't find any issue talking about my problem, so I declare it here.
I found a way to create same alias for 2 different nodes.

Steps to reproduce the issue
Install from scratch drupal 8.8.0-alpha1 (or maybe others versions of drupal core).
Enable the Language module.
Create a content type A with default language 'Not specified' or 'Not applicable'
Create a content type B with default language 'English' (or any other language of your drupal site)
Create a node A of content type A with for example '/test' as alias
Create a node B of content type B with the same alias

Drupal allows it : I have now 2 nodes with the same alias and I cannot access to my node A anymore. (even trying to access via /node/nid, beacause I'm redirected to the alias)

Proposed resolution

On the alias creation, drupal just checks if this alias isn't already taken in the current language.
I think it shoulds also checks in 'und' language.
I could purpose a patch about it but I would like have your opinions first.

Thanks,

NB: Same problem with pathauto (contrib module) but I think they use the same checks as core.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Path 

Last updated 6 days ago

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

🇫🇷France Quentin Massez

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇮🇳India er.garg.karan Chandigarh

    I am also facing this issue.

    Steps to reproduce

    1. Create a content type "Blog". Make sure you choose to show the language selector drop-down on the node create and edit page.
    2. Set the default language of the content type as "Not Specified".
    3. Go to blog add form.
    4. Choose the language as "French" and add a custom URL "/my-custom-url-for-blog".
    5. Save the node and you will be able to create the blog node.
    6. Repeat steps #3, #4, and #5 and you will be able to create a new node in French with the same URL "/my-custom-url-for-blog".

    Cause
    The class Drupal\Core\Path\Plugin\Validation\Constraint\UniquePathAliasConstraintValidator has validate function and it checks for the duplicate URL in a particular language. But the variable "$langcode" in line 49 gets the langcode from the path entity and it is always the default language you choose in Step #2. In my case, it is always "Not Specified".
    This works fine when you edit one of the blog because by this time, the language of path alias has been set to "French".

    Propose solution
    The language should be used from the language dropdown if it is visible on the node add form.

  • 🇮🇳India er.garg.karan Chandigarh

    I was able to create this patch. It works for multiple versions of Drupal.

  • Status changed to Needs review 12 months ago
  • last update 12 months ago
    29,782 pass, 14 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & MySQL 5.6
    last update 12 months ago
    Build Successful
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & MySQL 5.7
    last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    29,424 pass, 14 fail
  • Status changed to Needs work 30 days ago
  • 🇵🇱Poland tivi22

    Thanks er.garg.karan for the patch. I needed to adjust it a little, but it worked fine for me.

  • 🇮🇳India rajghai

    Upon using the patch , I was getting a below error while creating a new node:
    Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Input value "langcode" contains a non-scalar value. in Symfony\Component\HttpKernel\HttpKernel->handle() (line 83 of /mnt/www/html/marketing7dev/vendor/symfony/http-kernel/Htt
    pKernel.php).

    I have updated the patch.

  • Status changed to Needs review 20 days ago
  • Status changed to Needs work 20 days ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Status changed to Needs review 20 days ago
  • 🇮🇳India rajghai

    Here is the updated patch for comment no. 17.

  • Status changed to Needs work 15 days ago
  • 🇺🇸United States smustgrave

    Recommend using MRs as those get auto ran against the tests

    Also see most likely will need a test case.

  • 🇮🇳India Prashant.c Dharamshala

    Tried to reproduce the issue based on the steps mentioned in the issue summary, I am able to replicate the issue but as per the issue summary (even trying to access via /node/nid, because I'm redirected to the alias), this is not the case atleast in 11.x

    • When trying to access using /node/[nid]/ it is opening the correct node page
    • When trying to access using the node alias it is always opening the node i.e node of the content type in which Sites's default language(English) option was selected.
  • Pipeline finished with Failed
    6 days ago
    Total: 564s
    #203383
  • 🇮🇳India Prashant.c Dharamshala

    It still needs some work :

    1. MR needs to be reviewed.
    2. Some existing tests are failing
    3. As per #21 a new test case needs to be written.
  • Pipeline finished with Success
    6 days ago
    Total: 635s
    #203393
Production build 0.69.0 2024