Domain Config overrides use incorrect language on multilingual sites

Created on 13 August 2025, 3 days ago

Drupal Version

10.4.3

Domain module version

2.0.0-beta2

Expected Behavior

The Domain Config module should initialize the context with the correct language based on the active domain and URL language detection, ensuring that \Drupal::languageManager()->getCurrentLanguage() returns the expected language throughout the request lifecycle.

Actual Behavior

The language manager sometimes returns the wrong language. During debugging, the correct language (e.g., fr) is set initially but changes unexpectedly during processing. This results in overrides being loaded for the wrong language.

Steps to reproduce

  1. Set up two domains: site1.com and site2.com.
  2. Enable the Content Translation module.
  3. Add French (fr) as a site language.
  4. Configure language detection to use URL with language as a suffix (e.g., site2.com/fr).
  5. Visit https://site2.com/fr.
  6. With xdebug, Add a breakpoint in loadOverrides() at:

    // Set the context of the override request.
    if (!$this->contextSet) {
      $this->initiateContext();
    }
  7. At the breakpoint, check the value of:\Drupal::languageManager()->getCurrentLanguage()->getId()
  8. Continue debugging and observe the value change unexpectedly to fr during processing.

Additional Information

• The issue appears to be related to how the context is initialized when both Domain Config and multilingual URL detection are in use.
• I will attach a video demonstrating the debugging steps and the change in language value.

Proposed Fix

Compare the current language from the language manager with the DomainConfigOverrider language property. If they differ, re-initiate the context to ensure that the correct domain and language context is applied before overrides are loaded.

// Set the context of the override request.
      if (!$this->contextSet) {
        $this->initiateContext();
      }

      // Language has changed since we initiated context, so re-initiate.
      if ($this->languageManager->getCurrentLanguage()->getId() !== $this->language->getId()) {
        $this->contextSet = FALSE;
        $this->initiateContext();
      }
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇧🇷Brazil andre.bonon

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