Score:0

How can I use the custom image as thumbnail for Youtube videos?

eg flag

i want to use custom image as thumbnail for remote video (youtube) in my paragraphs , I create one field called custom image under remote video and used the below code.

if ($entity->bundle() === 'remote_video' && isset($entity->get('field_custom_image')->target_id)) {
  $entity->get('thumbnail')->target_id = $entity->get('field_optional_custom_image')->target_id;
}

The thumbnail image is replaced by a custom image in media view, but when I tried to use that media in page, it is still using the Youtube thumbnail image.

Any help on this is greatly appreciated.

Jaypan avatar
de flag
I set this up in the URL to Video Filter module (https://www.drupal.org/project/url_to_video_filter). You can examine the source code and JS to see how I did it. It's been a few years so I don't remember the specifics.
in flag
The thumbnail is determined by a MediaSource plugin (here's [oembed](https://github.com/drupal/drupal/blob/9.4.x/core/modules/media/src/Plugin/media/Source/OEmbed.php#L264) and here's [image](https://github.com/drupal/drupal/blob/9.4.x/core/modules/media/src/Plugin/media/Source/Image.php#L142) for comparison because it pulls from a field in the entity). It's that dropdown you select when you create a new media type. You just need to extend the oembed one and have it pull from a field on the entity like image. Then update the media type via config (since the dropdown is disabled after create).
vyshnavi avatar
eg flag
@Joseph HI joseph , can you please give me some example on how to do that one ?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.