Module does not work

Created on 11 June 2024, 7 months ago
Updated 26 August 2024, 4 months ago

Problem/Motivation

I just tested out this module, but it doesn't seem to work:

  • When creating a second node with the same title as another one ('Test'), but with another canonical domain, a unique alias is generated ('/test-0') instead of being able to reuse the existing path ('/test'):

    The automatically generated alias /test conflicted with an existing alias. Alias changed to /test-0.

  • After fixing this, when creating the same alias on multiple domains, all domains redirect to the same node, regardless of the canonical domain assigned to that node.

Proposed resolution

Instead of getting the domain from field_domain_source on the request, which only works when creating/updating a node, I think we should fallback to the current active domain. This way the overridden getPathByAlias function also works in path processors, outside the alias generation context.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dieterholvoet
  • 🇧🇪Belgium dieterholvoet Brussels

    I'm not sure where the field_domain_source_url field is supposed to come from. It doesn't seem to be part of the Domain module. I left it out for now, but feel free to add it back if necessary.

  • 🇧🇪Belgium dieterholvoet Brussels

    Something else I took the liberty to fix: when decorating a service, you're not supposed to extend the original class. You're supposed to implement the service, inject the original class and call it as a service when necessary. By doing this, you don't need to inject all dependencies the parent needs and the class won't break if the constructor of the parent changes.

  • Status changed to Needs review 6 months ago
  • Merge request !8Resolve #3453945 "Module does not" → (Merged) created by dieterholvoet
  • Pipeline finished with Success
    6 months ago
    Total: 149s
    #196521
  • 🇫🇷France jenue1933 Bordeaux

    Hi!

    LGFM, thx for your contribution. Can you update your MR and add some related functional tests plz?

  • 🇫🇷France jenue1933 Bordeaux

    field_domain_source_url came from my personal project. I forgot to clean it when I pushed on d.org.

  • Status changed to Fixed 4 months ago
  • 🇮🇳India chiragkparikh

    This works amazingly well, thanks!

    But when I was trying install this in an environment by importing config and there was no domain source assigned for any node, I used to get an error saying the function getDomainIdByRequest is returning NULL (when an empty string is expected).

    So, I modified that function slightly to fix this:

    public function getDomainIdByRequest(?Request $request = NULL): string {
        $request ??= $this->requestStack->getCurrentRequest();
    
        $domainId = $request?->request->get('field_domain_source')
        ?? $this->domainNegotiator->getActiveDomain()?->id();
    
        return $domainId !== null ? $domainId : '';
      }
    

    I hope this is fine!

Production build 0.71.5 2024