Add a hook to modify Media data

Created on 22 March 2019, about 5 years ago
Updated 12 March 2024, 3 months ago

I want to fetch the max resolution thumbnail from YouTube (1280x720), but OEmbed is providing only the the 480x360 thumbnail URL and there is currently no way to override that. Could a hook be provided to alter the OEmbed data? Currently one can only change the OEmbed url via hook_oembed_resource_url_alter().

{
  "author_url": "https://www.youtube.com/user/ZackScott",
  "provider_name": "YouTube",
  "height": 270,
  "thumbnail_width": 480,
  "thumbnail_height": 360,
  "width": 480,
  "version": "1.0",
  "html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/M3r2XDceM6A?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>",
  "title": "Amazing Nintendo Facts",
  "provider_url": "https://www.youtube.com/",
  "thumbnail_url": "https://i.ytimg.com/vi/M3r2XDceM6A/hqdefault.jpg",
  "author_name": "ZackScott",
  "type": "video"
}

Propossed solution

https://www.drupal.org/project/drupal/issues/3042423#comment-13414737 ✨ Add a hook to modify oEmbed resource data Needs work

I think maybe a hook to alter metadata in a generic way might be more useful. This also allows changing / adding metadata for non-oembed sources.
Not really sure yet what the best way would be to implement that. Each source has its own getMetadata() method and having all these methods call the alter hook might not be the best way.

https://www.drupal.org/project/drupal/issues/3042423#comment-14358053 ✨ Add a hook to modify oEmbed resource data Needs work

One possible way this could work is for MediaSourceBase, and all of its subclasses, to rename getMetadata() to protected function getRawMetadata(). MediaSourceBase::getMetadata() would then just call $this->getRawMetadata(), allow modules to alter the value, and then return it. This would be consistent, but it would require contrib and custom sources to rename their getMetadata() method to getRawMetadata() in order to become "alterable". But that seems like an acceptable API change to me; it won't break existing sites, but it will be required for this new hook to work.

Release snippet

New hook (hook_media_source_metadata_alter) is available in Media to hook into the generated data.

✨ Feature request
Status

Needs work

Version

11.0 🔥

Component
Media  →

Last updated 1 day ago

Created by

🇳🇱Netherlands José Trindade

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024