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 DomainListBuilder since 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

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

mably created an issue. See original summary.

  • mably committed 214aeb42 on 3.x
    task: #3578566 Domain::getLink() should include the path prefix in the...
mably’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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