Media SVG Thumbnail field formatter

Created on 26 February 2024, about 1 year ago

Problem/Motivation

There is a "Thumbnail" field formatter for fields that reference a media entity. This makes for much cleaner markup and allows for unlimited media display configurations per reference without having to build several display modes for the media entity. It would be extremely helpful to have an SVG version of this field formatter with this module.

Proposed resolution

A new field formatter (SvgMediaThumbnailFormatter) that allows directly displaying an SVG from a media reference field.

Feature request
Status

Active

Version

2.3

Component

Code

Created by

🇺🇸United States jayhuskins

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

Merge Requests

Comments & Activities

  • Issue created by @jayhuskins
  • Merge request !23Resolve #3423892 "Media SVG thumbnail" → (Open) created by jayhuskins
  • Status changed to Needs review about 1 year ago
  • 🇨🇦Canada mandclu

    I'm not against this idea, but the field seems to work fine with the media library without it. Can you clarify where or how this change would be visible?

  • Status changed to Postponed: needs info 4 months ago
  • 🇪🇨Ecuador jwilson3

    Co-maintainer here. I tested the patch but couldn't figure out how (or where) to use the new formatter in a practical way.

    For example, one place where I see Media Thumbnails being used is in the Media Library's default (table) view at /admin/content/media. Unfortunately, the formatter doesn't work in this context because the Views field config requires a single Image Style formatter for all media types. To work around this limitation, I created a Thumbnail view mode for all media types: Raster Images (and other media types) display the Thumbnail field with the 100x100 image style, while the Vector Image media type uses the main SVG field with 100x100 dimensions applied. Then, I updated the Media Library view to use a Rendered entity field with the new Thumbnail view mode and removed the Thumbnail field.

    In this case, a potential solution could be to adjust the Image formatter when used on an SVG's Thumbnail field to calculate dimensions based on the selected image style, combined with the module's "Inline SVG" and "Apply dimensions" features. While this is an opinionated approach, alternatives like injecting settings into the Image formatter or creating a UI for SVG-specific settings per image style are less desirable.

    In summary, and basically to restate what @mandclu said above, we need a better understanding and a practical situation where the Thumbnail field on the Vector Image media type is actually useful or required.

  • 🇮🇹Italy finex

    Hi, I came here because I'm having an issue with SVG media thumbnails. Here's my case: on the media management page, some SVGs appear huge even though the view settings are set to display 100x100px thumbnails. Now I'm forcing a custom CSS to make the thumb smaller but it's not a good solution.

  • 🇪🇨Ecuador jwilson3

    Hi @finex,

    1. Can you please try the workaround in #6, which has an approach that should resolve the issue for you. TL,DR; create a View Mode called "Thumbnail" for Media, and render the actual SVG Field instead of the bundled Thumbnail field. Then edit the Media Library view to not use "Media Thumbnail" field, but to display the Rendered Entity, and render the "Thumbnail" view mode.

    2. If this doesnt fix the problem, can you please provide some additional context, including:

    Which theme is being used?
    Screenshot of where the SVG is appearing too large.

Production build 0.71.5 2024