When installing drupal and using it with more than one language, some actions may not work for the language that is not the default one, such as, access the alias urls for the second language.

Reproduce
- Install drupal 8.6
- Enable locale, language and pathauto modules
- Install a second language such as spanish

- Set the language negotiation to:
> Interface text language detection
- User
- Selected language (spanish)

- Enable the option "Customize Content language detection to differ from Interface text language detection settings"
> Content language detection
- Content language
- User
- Selected Language (spanish)

- Create any content and set its language to spanish
- Using a user that has spanish language as its preference, try to access this new content.
- The page is not found.

I found some functions that are using the negotiation type url as default (LanguageInterface::TYPE_URL) when asking for the current language for the language manager service. This way, the service only looks for the language code in the url/domain and does not consider other types of negotiation.

Here is the list of files and functions that I found these problems

- file core/lib/Drupal/Core/Routing/RouteProvider.php at line 473
return $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId();

- file core/lib/Drupal/Core/Path/AliasManager.php at line 156 and 192
$langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId();

After removing the parameter type for the function getCurrentLanguage the system started working properly and resolved the url for both languages.

Other places that execute the same process and may break the system:
- core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php at line 95
- core/modules/contextual/contextual.module at line 177
- core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php at line 134
- core/modules/system/system.module at line 737

If the system really needs to have this negotiation as the default fallback I believe that the method getCurrentLanguage should the main responsible for setting this option inside its logic.

Comments

jhonatan.ambrosio created an issue. See original summary.

jhonatan.ambrosio’s picture

Assigned: jhonatan.ambrosio » Unassigned
jhonatan.ambrosio’s picture

Title: Set default negotiation to 'Url type' » Default language negotiation is set to 'Url type' wrongly in the core
Issue tags: +language
jhonatan.ambrosio’s picture

Patch that fixes the negotiation problem

vierlex’s picture

Status: Active » Needs review

Status: Needs review » Needs work

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Status: Needs work » Closed (outdated)
Issue tags: -language, -translation, -multilingual +Bug Smash Initiative

@jhonatan.ambrosio, Thank you for reporting this problem and making a patch. We rely on issue reports like this to improve Drupal core.

I tested this on 10.0.x, demo_umami install and was not able to reproduce this error. I followed the steps given in the Issue Summary.

Therefore, closing as outdated.

If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

Thanks!