Invalid page path when <current> is an absolute URL (incompatible with Domain Source module)

Created on 31 July 2024, about 2 months ago
Updated 16 September 2024, 12 days ago

Problem/Motivation

Drupal\editoria11y\Api expects page_path to be a root-relative URI. However, when this is set within editoria11y_page_attachments(), the URL generator can return absolute URLs, such as when the Domain Source module is installed and the current entity has a Domain record associated with it. This throws an exception that the path is invalid.

Steps to reproduce

  1. Install the Domain and Domain Source modules: composer require drupal/domain && drush en domain_source
  2. Visit /admin/config/domainand configure a domain record.
  3. Create a new node with a field_domain_source set to the domain.
  4. Visit the node to reproduce the error.

Proposed resolution

Parse and use the path component of the URL.

As a quick workaround, we implemented hook_page_attachments() in a custom module:

function mymodule_page_attachments(array &$attachments): void {
  if (isset($attachments['#attached']['drupalSettings']['editoria11y']['page_path'])) {
    $editoria11y = &$attachments['#attached']['drupalSettings']['editoria11y'];
    $parsed = parse_url($editoria11y['page_path'], PHP_URL_PATH);
    $editoria11y['page_path'] = $parsed ?: $editoria11y['page_path'];
  }
}
πŸ› Bug report
Status

Fixed

Version

2.1

Component

Conflicts with other modules

Created by

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

Comments & Activities

  • Issue created by @nicross-com
  • Assigned to itmaybejj
  • πŸ‡ΊπŸ‡ΈUnited States itmaybejj

    Oof. So this module family creates a pseudo-multisite with multiple domains being served from one DB?

    If that is the case, I don't think we should drop the domains from the url -- you'll want them later, to search and filter the API reports. Probably better to rewrite the not-much-better-than-a-placeholder Editoria11y API path validator to accept absolute paths. Maybe that should be replaced with a call to PathValidator or something like that?

    This may have some downstream affects on the views as well; that would need to be tested once the API was accepting absolute URLs.

  • Thanks for considering this. That sounds like it could be a more robust solution than our simple workaround.

    The reason why the workaround works for us is because, even with the Domain Source module installed, our path aliases are still required to be unique. So we have aliases like /domain1/home and /domain2/home where the reporting still makes sense to us without a domain present. We also have domain aliases set up for our different environments, like a dev.domain1.com or staging.domain2.com, which complicates it further.

    Granted, we have a lot of custom code gluing this together, so supporting a full URL here might still be the better general solution.

  • Status changed to Needs review 19 days ago
  • πŸ‡ΊπŸ‡ΈUnited States itmaybejj
  • Status changed to Fixed 12 days ago
Production build 0.71.5 2024