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();
      }

Issue fork domain-3541242

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andre.bonon created an issue. See original summary.

andre.bonon’s picture

Issue summary: View changes
mably’s picture

Hi @andre.bonon, thanks for your detailed issue.

If I understand it correctly, the current language can changed after the domain context has been initialized.

May be we could simply avoid storing the current language as a class property, what do you think?

mably’s picture

Status: Active » Needs review

Hi @andre.bonon, I have created MR 167 that uses a different approach.

I simply added a kernel event subscriber that gets called after language negotiation has occurred.

I then update the language property of the DomainConfigOverrider class using a new setLanguage method.

Could you give it a try and tell me if it solves your problem?

You could still have a problem if you need to get a domain language overridden configuration before language negotiation has occurred. But not sure if we can handle that particular case.

What is still missing here is a test . Sadly I haven't been able to reproduce your problem locally.

andre.bonon changed the visibility of the branch 3541242-domain-config-overrides to hidden.

andre.bonon changed the visibility of the branch 3541242-domain-config-overrides-beta3 to hidden.

andre.bonon’s picture

Status: Needs review » Reviewed & tested by the community

Works for me on Drupal 10.4.3.
I was able to see the language being updated during the process, and I could retrieve the right config values.

  • mably committed 7e76637e on 2.0.x
    Issue #3541242 by andre.bonon, mably: Domain Config overrides use...
mably’s picture

Assigned: andre.bonon » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.