Fatal error when linking SVGs to file

Created on 11 November 2024, about 1 month ago

Problem/Motivation

In some cases, linking an image can lead to a fatal error. This seems to be a regression from 🐛 Link missing on SVGs with responsive image formatter Active .

Steps to reproduce

  • Configure an entity view display with an image field to use the responsive image formatter and set "Link image to" to "File".
  • Upload an SVG file into an image media (the error won't occur with non-SVGs).
  • View a node that references that media.

The error is caused due to inconsistent URL handling in the parent formatter: core's ResponsiveImageFormatter creates an object of type \Drupal\Core\Url when the "Link image to" setting is set to "Content", but a string (as the result of $file->createFileUrl() when it's set to "File".

As we take the URL from the parent formatter and use it in a link render array, that fails with a string because it always expects a URL object.

Proposed resolution

Convert the string to a URL object.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.1

Component

Code

Created by

🇩🇪Germany mrshowerman Munich

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024