Wrong Language is chosen and no node visibe under certian conditions

Created on 22 October 2021, about 3 years ago
Updated 13 June 2023, over 1 year ago

Problem/Motivation

In some cases, a redirect is successfully created and some users (in my case) anonymous users can see the node on the alias, but logged-in users get a 404 on the same page.

This happens when there is a mismatch in languages

Steps to reproduce

  • Create a site with many languages on different domains
  • Log in as a user who has a different administration language to the language of the site
  • Create a node with a domain alias in the language of the site
  • View that node alias as an anonymous user and you can see it
  • View the node alias as the logged-in user and you get a 404

Proposed resolution

It looks like https://git.drupalcode.org/project/domain_path/-/commit/1df8666 changed the way the default language was determined.

From:

$this->languageManager->getCurrentLanguage($this->method)->getId();

To

$this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();

Method is defined at the start of the function (quite why it is used in the object scope I don't know)

 $this->method = $config->get('language_method') ? $config->get('language_method') : LanguageInterface::TYPE_CONTENT;

What this means is that if a method other than LanguageInterface::TYPE_CONTENT is used there will be a mismatch between the method used to get the path and the language expected.

Reverting this change seems to resolve the issue.

Remaining tasks

Make patch and merged

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom JeremyFrench

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.

  • 🇬🇧United Kingdom nicholasthompson

    I have ended up debugging this in #3362515 and in my case, I have a non-multilingual site.

    The content (for whatever reason) is in a mix of "en" and "und"... however due to the NULL check, this line will always try to resolve to what I assume is the current language for the content?

    $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
    

    For some reason I've yet to work out, the node in question is set to "und" (as is the domain source and domain path)... however this causes NULL to change to "en". I'm guessing this is because Drupal defaults the site language to "en" rather than "und"?

    This causes the domain_path lookup to fail and it falls back to something else making the page access denied.

    This is the same behaviour in 8.x-1.2

    The patch from @JeremyFrench does not help in my case... in fact, for me, the best fix is to simply remove the line altogether... I assume this is a poor choice for other sites? Although does this mean other sites should fall back to using the alias for the language of the content, rather than the language of the site itself?

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom nicholasthompson

    For reference, this is my change - however I'm almost certain this is not the right fix for everyone.

  • 🇬🇧United Kingdom cameronwelch

    the above caused an issue for me where aliases set to english would no longer be recognised - here's the patch I'm using instead

Production build 0.71.5 2024