Surface file variables to media twig

Created on 9 November 2023, over 1 year ago

Problem/Motivation

From a site building perspective it's very common to focus attention on the media types, both from a content management and a theming perspective. So it's common to have "document" media type that allows a single file, however theming this with just core, say showing and icon for the file mime, file url, a file size, and the media name is surprisingly complex. Some considerations are:

1. File formats such as Generic File are ignorant of the media name.
2. Accessing the file elements from the media template is relatively complex, being a field list of entities on a field
3. The field the files are on can change
4. Examples you find on the web often need to focus on multiple files, and can be confusing.
5. There are many modules, but it feels like they shouldn't be needed.

Proposed resolution

Surface the following twig variables into the media template by default. Obviously naming is a challenge, and how to delineate between what is meta and what is renderable.

  • file_entity.single_fileHas a single file (any twig examples should check this)
  • file_entity.sizeFirst file size
  • file_entity.mimeFirst file mime (note that mime class is output in attributes of File entities)
  • file_entity.filename
  • file_entity.uri
  • ...

Alternatively:

  • file_meta.countNumber of files (or just test for length)
  • file_meta.N.size
  • file_meta.N.name
  • file_meta.N.filename
  • ...

I wonder should a site builder be able flag that a media bundle should surface information about a primary file, or if there is enough logic to do this automatically.

Remaining tasks

  1. I'd love to get some solid input whether this is a valuable addition to core
  2. Potentially I will code some of this as i seem to code something like this for every project anyway

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated 37 minutes ago

Created by

πŸ‡¦πŸ‡ΊAustralia sime Melbourne

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

Comments & Activities

Production build 0.71.5 2024