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

Created on 31 July 2024, 4 months ago
Updated 16 September 2024, 2 months 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

Production build 0.71.5 2024