Language negotiation breaks updating Drupal 9 to 10

Created on 6 September 2023, over 1 year ago
Updated 20 February 2024, 10 months ago

Problem/Motivation

Language negotiation in core changed from Drupal 9 to 10, breaking things.

I have a piece of code in an openid_connect module to generate an internal URL, like this:

    $language_none = \Drupal::languageManager()
      ->getLanguage(LanguageInterface::LANGCODE_NOT_APPLICABLE);

    $redirect_uri = Url::fromRoute(
      'openid_connect.redirect_controller_redirect',
      [
        'openid_connect_client' => $this->getPluginId(),
      ],
      [
        'absolute' => TRUE,
        'language' => $language_none,
      ]
    )->toString(TRUE);

Which in Drupal 9 generated something as "https://mysite.com/openid_connect/acm-idm". I have language negotiation active, but the LanguageInterface::LANGCODE_NOT_APPLICABLE killed the language prefix.

I updated to Drupal 10 and then the behaviour changes: I get as output "https://mysite.com/nl/openid_connect/acm-idm" (note the "nl" prefix).

Looking at the code I end up in "Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl.php" in function "processOutbound":

In Drupal 10 there's code in there like this:

    if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && in_array($options['language']->getId(), [
      LanguageInterface::LANGCODE_NOT_SPECIFIED,
      LanguageInterface::LANGCODE_NOT_APPLICABLE,
    ]))) {
      $language_url = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL);
      $options['language'] = $language_url;
    }

In Drupal 9 the in_array() part above is not present.

If the language option I set is "LanguageInterface::LANGCODE_NOT_APPLICABLE" I do not want the language prefix to be added. If the LanguageInterface::LANGCODE_NOT_APPLICABLE is removed from the array above all is ok again.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
Language module 

Last updated about 11 hours ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024