Problem/Motivation
When path prefix mode is enabled, Domain::getLink() uses getCanonical() (the bare hostname) as the link text. This means the DomainSwitcherBlock displays links like:
- example.com
- example.com (for the "fr" prefixed domain)
Users cannot distinguish between domains because the prefix is missing from the link label. The link URL is correct (http://example.com/fr/), but the visible text does not reflect it.
Proposed resolution
Modify Domain::getLink() to append the path prefix to the canonical hostname when a prefix is set:
$label = $this->getCanonical();
if ($this->getPathPrefix() !== '') {
$label .= '/' . $this->getPathPrefix();
}
This produces link labels like example.com/fr instead of just example.com.
Additionally:
- Update the
DomainInterface::getLink()docblock to document the new behavior and fix the return type description ("Returns a generated link" instead of "Returns a URL object"). - Remove the separate "Prefix" column from
DomainListBuildersince the hostname link now includes the prefix — avoids displaying the prefix twice. - Update
DomainPrefixFunctionalTest::testSwitcherBlockLinks()to expect the prefix in the link label.
Remaining tasks
- Review the patch.
- Verify
DomainNavBlock(which has its own label logic) is unaffected.
Related
All callers of getLink():
DomainSwitcherBlock::build()— benefits automatically.DomainListBuilder::buildRow()— the separate prefix column is removed to avoid duplication.
Not affected: Drush commands use getHostname(), not getLink().
Issue fork domain-3578566
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 #4
mably commented