Media substitution plugin renders absolute paths

Created on 8 February 2023, almost 2 years ago
Updated 17 March 2023, almost 2 years ago

Problem/Motivation

The Media and File plugins use a deprecated function that renders absolute paths in the html output. In web/modules/contrib/linkit/src/Plugin/Linkit/Substitution/Media.php line 51 uses this code:
$url->setGeneratedUrl(file_create_url($file->getFileUri()));
The function file_create_url is deprecated and instead $file->createFileUrl()) should be used. This function renders a relative path by default which I think also solves the problem with absolute url's in a related issue 2829173 ✨ File is inserted with absolute URL Fixed .

Proposed resolution

Instead of using this:
$url->setGeneratedUrl(file_create_url($file->getFileUri()));
we should use this:
$url->setGeneratedUrl($file->createFileUrl());

πŸ› Bug report
Status

Closed: duplicate

Version

6.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands edwin.van.buuringen Den Haag

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

Comments & Activities

  • Issue created by @edwin.van.buuringen
  • Status changed to Needs review almost 2 years ago
  • πŸ‡³πŸ‡±Netherlands edwin.van.buuringen Den Haag

    Adding a patch that fixes this for the media plugin replacing the deprecated code with createFileUrl.
    Although the samde deprecrated function is also use in linkit/src/Plugin/Linkit/Substitution/File.php I haven't (yet) investigated if the same solution makes sense there.

  • Status changed to Closed: duplicate almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for reporting this!

    Based on my evaluation, this can be considered a duplicate of ✨ File is inserted with absolute URL Fixed , whose patch reflects more recent code changes and is more comprehensive.

Production build 0.71.5 2024