I want to create embeddeable "media" similar to how embedding YouTube or Vimeo videos work. When a URL is pasted in, I want to store this as a media entity (its own type) and then render it out with an oEmbed formatter (it has an iframe tag and attached JS library). This way, adding them for editors is easy and later re-usable for embedding as media objects. Where do I look in the Media system to support this? (note - its not images or video)
1 Answer
If it supports oEmbed you can use OEmbed
Source plugin similar to below.
https://git.drupalcode.org/sandbox/Bhanu951-3225164/-/blob/1.x/src/Plugin/media/Source/TikTok.php
If it doesn't support oEmbed you can create your own media source plugin extending MediaSourceBase
class similar to below.
Edit 1 :
In order to store it as own media type you need to extended oEmbed
class and define providers
key to provide oEmbed source. All the additional metadata will be handled by oEmbed
class.
You can alter the source data by using hook_media_source_info_alter
refer
https://git.drupalcode.org/sandbox/Bhanu951-3225164/-/blob/1.x/media_entity_tiktok.module#L11
-
Huh, no code within it? How can I store it as its own media type? The service does support OEmbed.– KevinCommented Jun 7, 2022 at 2:40