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
- Set up two domains: site1.com and site2.com.
- Enable the Content Translation module.
- Add French (fr) as a site language.
- Configure language detection to use URL with language as a suffix (e.g., site2.com/fr).
- Visit https://site2.com/fr.
- With xdebug, Add a breakpoint in loadOverrides() at:
// Set the context of the override request. if (!$this->contextSet) { $this->initiateContext(); } - At the breakpoint, check the value of:
\Drupal::languageManager()->getCurrentLanguage()->getId() - 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();
}
| Comment | File | Size | Author |
|---|---|---|---|
| Screen Recording 2025-08-13 at 18.47.51.mov | 22.84 MB | andre.bonon |
Issue fork domain-3541242
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
Comment #2
andre.bononComment #3
mably commentedHi @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?
Comment #6
mably commentedHi @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
setLanguagemethod.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.
Comment #10
andre.bononWorks 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.
Comment #12
mably commented