[Meta] Consider adopting Media Widgets as an experimental feature

Created on 27 November 2024, 25 days ago

Problem/Motivation

The Media Widget → module was developed as part of a client project with the goal of being ready when Drupal core would eventually adopt media entities as the default choice over raw file entities. The module defines a basic upload widget for media types not allowing to reference existing entities, except from the current one.

Additional project requirements were to define a single Link widget capable of handling any URL the user could enter: a URL could represent an OEmbed resource, a plain link, or even a non-OEmbed resource to be embedded in the site page via custom markup. This was implemented through the following strategy:

  • The Media Widget → module exposes an OEmbed media widget mimicking the core one provided by the media library, but without the ability to reference existing media items.
  • The Media Link → module defines a new Link media source and replaces the OEembed media widget class with a new implementation allowing to fall back to a raw link media item if no OEmbed provider matches the given URL.
  • The Media Remote Embed → module defines a new Remote Embed media source and replaces the Media Link OEmbed media widget class with yet a new implementation allowing to detect a custom embed provider in the given URL. If no such provider is found, the widget falls back to a raw link media item, unless a matching OEmbed provider is found.

This allows to handle all sorts of user inputs via media items, which in turn opens the possibility for further improvements. Aside from reusability, which admittedly was not a concern for our project, this allows to generate media previews for each media source: an image just needs a thumbnail, but a PDF document can get a set of images representing the various page, a link media item can get an image + textual metadata, for instance via OpenGraph. This is of course just an example, although a (not yet published) Media Preview suite has been implemented as well, to address many of the cases described above.

Proposed resolution

Consider adopting the Media Widget ecosystem as an experimental feature as a first step to evaluate core inclusion.

Remaining tasks

  • Discuss the proposed solution
  • Review the existing code
  • Create implementation tasks

User interface changes

The media widgets are still a bit rough, since their theming was heavily customized as part of the client project, here is a set of screenshots showing how to set the modules up and how the end result looks like on a vanilla Drupal installation:

API changes

None foreseen.

Data model changes

None foreseen.

🌱 Plan
Status

Active

Component

Track: Media Management

Created by

🇮🇹Italy plach Venezia

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

Comments & Activities

  • Issue created by @plach
  • 🇦🇺Australia pameeela

    I'll let @tonypaulbarker weigh in on this, unless I find time first!

  • 🇬🇧United Kingdom tonypaulbarker Leeds

    Thanks @plach. I will take these for a spin.

  • 🇮🇹Italy plach Venezia
  • 🇮🇹Italy plach Venezia
  • 🇮🇹Italy plach Venezia
  • 🇮🇹Italy plach Venezia

    Here is the corresponding core issue (postponed on this one):

    🌱 [PP-1] [Meta] Consider adopting Media Widgets as an experimental feature Active

  • 🇬🇧United Kingdom tonypaulbarker Leeds

    @plach I have had a little look (in fact I did take a look at media widget a little while ago) and these modules are on the way to finding solutions for features we were discussing that we would like to have so I intend to look in lots more depth at these. Here are some very early notes for myself and they may offer you some early insights. I will go through in more detail and take some screenshots / produce a few wireframes to better describe some of the discussion points. I began a meta issue to list the upcoming opportunities for media management, which is at https://www.drupal.org/project/drupal_cms/issues/3488393 🌱 [META] Vision for Media Management Active

    - Media can begin from a URL (as in the case of remote video) as well as an upload.
    - I think we should be able to use the media library to use existing media.
    - Bulk uploads is a consideration.

    So I think we have three cases of initialisation that we should support (new upload, new URL and existing media). This may lead us to end up with something similar to the media library UI, except that there should be no need to pre-select a media type before uploading (it's at least one click that we can save). As a bonus, bulk uploads would be possible along the lines of https://www.drupal.org/project/simple_media_bulk_upload → and the media types of the bulk uploads would be detected. In the long run, I would love to have some detection that a file already exists if the same is re-uploaded.

    We should be able to handle custom media entities that may share some filetypes with other media entities.

    Once the media entity is place, there is some UX / UI work because the I think the out of the box experience is currently quite confusing. I think we should be able to get to edit the media entity. We plan to have a small number of additional fields on media entities for filtering the library and for SEO.

    In the case of allowed URLs, content security policy comes to mind. Modules like Seckit are not easy to configure but by installing or approving only certain URLs / providers in the UI we can improve the situation. We might consider a validation of known and approved providers instead of rendering a link.

  • 🇫🇮Finland lauriii Finland

    This is definitely solving a pain point that I've heard mentioned in many conversations with Drupal users. However, many of these sites are re-using media and it would be great if we could solve this in a way that doesn't get rid of the re-use media part. I think there are ways in which this could be solve so that we would have both.

    This is not the only pain point that I've heard mentioned related to inserting media. Maybe we should do a more holistic design effort around how media gets referenced from content types to try to design something that could solve more of these problems at once? We don't have to implement all of these at once but having a north star design would be more likely to get us an overall better experience. It looks like some of these considerations are already being documented in 🌱 [Meta] Consider adopting Media Widgets as an experimental feature Active .

  • 🇬🇧United Kingdom tonypaulbarker Leeds

    @lauriii I think you have linked to this same issue?

    I think the holistic view comes in three main parts for the UI

    1. Initiating the upload / URL or library as discussed here.
    2. Interacting with the media library
    3. Enabling editor to set transformations and properties of an instance that uses a media field and getting some live feedback.

    and under the hood I think these will be the main considerations to achieve it:

    1. Field Widgets.
    2. Entity usage.
    3. System handling of transformations and image styles.

    I am doing some work to map out those problems and possible approaches, but I expect big changes that can take a while so in the meantime if we have the opportunity to improve the experience with smaller changes I think we should try to do it.

  • 🇮🇹Italy plach Venezia

    @lauriii

    However, many of these sites are re-using media and it would be great if we could solve this in a way that doesn't get rid of the re-use media part. I think there are ways in which this could be solve so that we would have both.

    In terms of what is possible right now, the widgets defined by Media Widgets were thought explicitly with non-reusability in mind: they mimic the Media Library widgets without offering the ability to select existing media. A site needing to support use cases could certainly enable both the Media Library widget on re-usable media reference fields (e.g. an article content type only authored by the site's editorial team) and the non-reusable Media Widgets for other use cases, e.g. user pictures.

    An approach I've been thinking about, but that I didn't have the opportunity to explore is conditionally enabling the existing media selector depending on permissions: a less privileged user could only upload new media items (or enter new URLs), while a more privileged one could have access to the Media Library as well. From the implementation perspective, this would likely mean always using the Media Library widget and tweak its logic to make access to the existing media selection UI conditional.

  • 🇮🇹Italy plach Venezia
Production build 0.71.5 2024