Decoupled website - absolute URL

Created on 12 October 2023, about 1 year ago
Updated 16 May 2024, 7 months ago

Problem/Motivation

We currently have a decoupled website in place and when a user references a media entity. The file is rendered with a relative urls which does not work well on a decouple website.

Steps to reproduce

- Add a Media Matcher
- Restrict the bundle to document
- Use the Direct URL to media file entity
- Try to link to a document in a wysywig
- Notice that the url is a relative one
- So when the text in the wysywig gets pulled over in a decoupled website, the relative urls won't work

Proposed resolution

- Could we have something like a checkbox (`absolute?`) when we select the "Direct URL to media file entity" subsitution type in the matcher?
- We could then use the value in the getUrl option in the `Linkit/Subtitution/Media.php` file

$is_absolute = checkAbsoluteCheckbox();
$file_url_generator->generate($file->getFileUri())->setAbsolute($is_absolute);
✨ Feature request
Status

Active

Version

7.0

Component

Code

Created by

πŸ‡²πŸ‡ΊMauritius whiz11

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

Comments & Activities

  • Issue created by @whiz11
  • πŸ‡²πŸ‡ΊMauritius whiz11
  • πŸ‡²πŸ‡ΊMauritius whiz11
  • πŸ‡²πŸ‡ΊMauritius whiz11

    Adding temporary patch to get the absolute url for now

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    88 pass, 1 fail
  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for reporting this. You are absolutely (sorry!) right that this module is now designed to provide relative URLs, both for media and for internal links.

    Since this issue was written up as specifically relating to the output of media entity URLs using the "Direct URL to media entity" setting, I'm curious whether you do not encounter this as a problem for other types of entity links on the decoupled site? Or do you just reference media entities?

    My inclination is that a more comprehensive solution would be to use the Pathologic module ( https://www.drupal.org/project/pathologic β†’ ), added to your text format filters, executing after the Linkit (and any other URL-based) filters, so you can ensure that the links are rendered as absolute, with whatever base URL is appropriate for your decoupled site.

    If there's a reason that approach wouldn't work, I'd love to hear about it.

  • πŸ‡²πŸ‡ΊMauritius whiz11

    I tried the Pathologic module and it does fit my use case. Thanks for showing the way :)

  • πŸ‡²πŸ‡ΊMauritius whiz11

    Actually, there is a nag. I only need this for media entities because we are gettting media files from the backend. But as for other links, they need to stay relative so that it continues work on the frontend. When I use the pathologic module, everything becomes absolute and the issue is if we have links that's supposed to work on the frontend, they stop working since they are now pointing to the backend.

  • Status changed to Active about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    I only need this for media entities because we are gettting media files from the backend. But as for other links, they need to stay relative so that it continues work on the frontend.

    Okay, thanks for the additional information. On the surface, this scenario sounds like an edge case that might best be solved by a code-based override to the Media entity suggestion plugin. I can try to work on a proof of concept for that when I have a chance, but I would welcome anyone else who is looking for a similar solution to take that approach and share their solution here.

    Setting issue status from "Postponed" to "Active."

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    The attached patch will cause only the "Media" substitution to render an absolute URL, per the request here. This would alter the default behavior of the module, and I don't plan to include this in the module as-is, people needing an absolute URL in this context could patch the module as a solution.

    An alternative would be to define a new Substitution plugin (e.g., id = "media_absolute") that would differ only from the current Media substitution plugin in this small regard shown in the patch. That would allow sites to opt in to this behavioral choice. Unfortunately, it wouldn't retroactively change existing links, since the text markup stores which substitution plugin is used (e.g., data-entity-substitution="media").

    If/when #3058983: Support changing substitution plugins on a matcher without having to re-enter content β†’ lands, that would no longer be an issue, but for the time being, this is the situation.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
Production build 0.71.5 2024