Problem/Motivation

The Domain Source module provides an OutboundPathProcessor to rewrite the path to entities to its configured Domain Source. However, there is no need to rewrite URLs when the source is the active domain.

Steps to reproduce

  1. Install standard profile
  2. Enable Domain source for Article
  3. Notice all entity links for an article are absolute URLs

Proposed resolution

Do not rewrite outbound URL if the source domain is the active domain

Remaining tasks

  1. Write a merge request
  2. Review
  3. Commit

User interface changes

URLs for an entity with a Domain Source are relative when the Domain Source is the active domain

API changes

None

Data model changes

None

Issue fork domain-3529385

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

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review

The merge requests updates the Domain Source OutboundPathProcessor to not rewrite the outbound URL if the source domain is the active domain

mably made their first commit to this issue’s fork.

mably’s picture

mably’s picture

Status: Needs review » Needs work

Hi @idebr,

I'm stuck on a functional test that runs fine on current version (D11) but fails on previous major (D10) when executed via a Gitlab CI pipeline.

Test works perfectly fine locally on D11 and on D10.

No idea what the problem could be.

Any help will be greatly appreciated.

mably’s picture

For now, I just disabled those 2 assertions when running on D10 in Gitlab CI.

Could you give it a try locally on D10 just to be sure we are not letting something go thru?

mably’s picture

After generating some logs on Gitlab CI, I can see that the failing node doesn't seem to have the right domain source defined:

----------------------------------------
Path: /node/1
Active domain: example_com
Langcode: en
Url: route:entity.node.canonical;node=1
Entity id: 1
Source id: example_com

Here is what I get when run locally:

----------------------------------------
Path: /node/1
Active domain: example_com
Langcode: en
Url: route:entity.node.canonical;node=1
Entity id: 1
Source id: four_example_com
Base URL: http://four.local-drupal10.sid.bm

What is rather strange is that we are testing the source just before doing the toString() :

    // Try to post a node, assigned to the second domain.
    $edit = [
      'title[0][value]' => 'Test node',
      'field_domain_source' => $two,
    ];
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->statusCodeEquals(200);
    $node = $node_storage->load(1);
    // Check that the value is set.
    $value = domain_source_get($node);
    $this->assertEquals($two, $value, 'Node saved with proper source record.');

    // Test the URL.
    $url = $node->toUrl()->toString();
    $expected_url = $two_path . 'node/1';
    $this->assertEquals($expected_url, $url, 'URL rewritten correctly.');
mably’s picture

Found the problem after a few hours of debugging.

The test relies on the order of the results of call to loadMultiple().

For some reason, the order is different on Gitlab than locally and the test fails.

Don't know for what reason it has been done like this.

For sure they didn't need to take the active domain into account then.

We do now, and on Gitlab CI, the test domain chosen was simply the already active domain.

So it couldn't work.

Test has been updated to be sure to avoid selecting the currently active domain.

mably’s picture

Status: Needs work » Needs review

@idebr everything is green again.

Do you want to have a look before I merge?

mably’s picture

Issue tags: +next-release
idebr’s picture

Changes look good. However, there is still an open thread in the merge request that is possibly outdated?

  • mably committed b7392417 on 2.0.x authored by idebr
    Issue #3529385 by idebr: Do not rewrite outbound URL if the source...
mably’s picture

Status: Needs review » Fixed
Issue tags: -next-release

It's merged. Thanks!

Status: Fixed » Closed (fixed)

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