Field formatter for video

Created on 19 February 2025, 2 months ago

Problem/Motivation

(Before releasing 3.0.0, I hastily dropped the video processor in the thunder submodule 📌 Drupal 11 compatibility fixes for custom_elements 3.x Active , because it was based on the nearly-unmaintained / D11-incompatible video_embed_field module. However: )

Having a field formatter for video (embed URL) is useful general functionality.

Proposed resolution

  • Introduce a formatter that is based on some code we have internally (and then start using this contrib code instead)
  • for media entities
  • Core-only functionality is not a good fit for us. We'll need to extend the OEmbed class. For this reason, it should probably be in a custom_elements_video submodule.
  • Enable other code to customize these embed URLs, based on video provider, because we can't support everything/everyone out of the box.
    • I'm thinking of an extremely light 'plugin/processor' system (no separate manager class; register services just like we do with processors; a service has a single public method)
    • Not because we want to invent something new, but because we have to. (I have checked around if anyone else has the same use case and I'm so far not seeing anything.)

Copy-pasting some analysis that I did for rewriting our internal code from video_embed_field to Core:

  • I at first thought that all video_embed_field functionality was available in Core. It unfortunately isn't.
    • The functionality we use is: simply transforming a source value to a video embed URL and thumbnail URL.
    • Example source field value (stored in media entity) is also a URL: https://www.youtube.com/watch?v=gEH291mq48Y&t=7s
    • video_embed has a system of plugins to transform this field into some render array / URL
      • a plugin 1. says whether it can handle the source value; 2. does the transformation
      • It has no method to get "embed URL", but we can pick it out of a render array for the "embed HTML".
      • Youtube plugin does this only using the source value (without making any HTTP request, at least not to an oembed endpoint)
    • Core has a single "media source" for video ULs: OEmbed.
      • OEmbed does not care about our functionality. It is based simply around a remote server returning a "embed HTML snippet".
      • The Core OEmbed class has a function for getting "URL" property, which does not work for video
        • and a function for getting "thumbnail URL" property, but it's not good by default / needs transformation.
      • Maybe we can get the OEmbed functionality (idk: HTTP query params?)... but that would require transforming the media source value before doing the request, which is no better.
    • We ideally don't want a HTTP request at all.
  • The video_embed_field project has been very minimally maintained for years (at least until December 2024; it has some activity and a D11 release now, but still.) Relying on it for our functionality is a risk.
    • I cannot find any mention of their "plugins" that we are using, or separating this functionality from the field itself (that we are not using). It seems to not be on anyone's mind. Apparently our application (just deriving an "embed URL, no HTML snippet" from the source value) is quite niche?
    • Ideally, we would move this to a CE field formatter in custom_elements. Relying on video_embed_field IMHO is not an option, for any contrib code we'll maintain.

Given that opinion: this needs extra 'glue', to fit our functionality onto Core code. The only realistic way is to override the "video:oembed" plugin class. (It uses other classes inside its getMetadata('url') call, but those are unreachable / marked as internal / based on fetching remote data, which we don't want.)

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

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

Comments & Activities

Production build 0.71.5 2024