Problem
When Domain Alias resolves a request via hook_domain_request_alter(), the domain stored in the negotiation context retains its canonical hostname instead of the alias hostname. For example, if the request comes in on staging.example.com (an alias for example.com), the active domain's hostname is example.com.
This works today only by accident: every code path that needs a hostname reloads the domain from storage, which triggers hook_domain_load, which rewrites the hostname. Comparisons use entity IDs, never hostnames. But any code calling $negotiator->getActiveDomain()->getHostname() directly gets the wrong value.
Steps to reproduce
- Create a domain
example.com - Create a non-default alias
staging.example.compointing to it - Visit
staging.example.com - In a hook or custom code, call
\Drupal::service('domain.negotiator')->getActiveDomain()->getHostname() - Result:
example.com(canonical) instead ofstaging.example.com(alias)
Root cause
In DomainResolver::resolveDomain(), after hook_domain_request_alter fires, the domain is returned with the canonical hostname. The alias hostname rewriting only happens later in hook_domain_load, which cannot run at negotiation time because the active domain is not yet set.
Proposed fix
Apply the alias hostname rewriting in hook_domain_request_alter itself, so the domain returned by resolveDomain() already has the correct hostname. This would make the active domain in the context immediately correct and remove the dependency on hook_domain_load for the active domain's hostname.
Note
This is a pre-existing bug, not a regression. The same pattern existed in the old DomainNegotiator::setRequestDomain() before the DomainResolver refactoring.
Issue fork domain-3583723
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 #3
mably commentedComment #5
mably commented