25 May, 2021
While having oEmbed support in the Drupal core is great, there are a few key requirements that might still be missing. In this blog we shall try out the oEmbed Providers module that extends the core’s media oEmbed functionality. The oEmbed Providers module is compatible with Drupal 8.8.4 version and above (and also works with Drupal 9!).
What is oEmbed Technology?
According to oembed.com, oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.
Basically, oEmbeds allows a website’s content to be embedded to another web page. The oEmbed format is supported by the most popular resources with multimedia content – Facebook, Twitter, YouTube, Instagram, Flickr, Vimeo and many more.
Configuring oEmbed Providers on Drupal
Step 1: Enabling the Media and Media Library core module
- Enable the media and media library core module in your site.
Step 2: Install and Enable the oEmbed Providers module
- Download the oEmbed Providers module using your method of choice (composer recommended).
$composer require drupal/oembed_providers
- Enable the module in your site.
Step 3: Configuring the oEmbed Providers module
- Once enabled you can visit the configuration form at /admin/config/media/oembed-providers.
- This module provides several features as listed below by extending core’s oEmbed functionality:
a. Add custom oEmbed providers
▪ Core Media provides no option for adding custom providers. The oEmbed providers module lets you do that by navigating to Configuration > Media > oEmbed Providers > Custom Providers and clicking on Add oEmbed provider.
• Fill in the necessary details to define a custom oEmbed provider and save the configuration form. Now you will be able to embed videos from this custom provider into your Drupal site. Here, I have given an example of a RadioPublic provider, you can fill in details of providers of your choice.
b. Global enable/disable providers
▪ The oEmbed Providers module provides an user interface for enabling and disabling providers.
c. Modify the providers list URL
▪ The oEmbed Providers module provides an user interface to alter the providers URL as the core Media module by default fetches the list of providers from here.
d. Disable the fetching of providers list
▪ The oEmbed Providers module provides an user interface to disable the external fetch of providers, for instance, when the site uses only custom providers.
e. Provides hook_oembed_providers_alter()
▪ The oEmbed Providers module provides a hook_oembed_providers_alter() that lets to alter provider definitions.
Step 4: Adding media to a content
- Once you’re done adding a custom oEmbed provider, you can now embed the videos from that custom provider into your Drupal site.
- Add a media field to any of your content types and choose ‘Remote Video’ media type.
- Now provide a video link from your custom provider. Here we have created a RadioPublic provider and saved the content.
Okay, that’s it! You can now see the videos from your custom provider being rendered on your Drupal site.
Please Note: Once you get your custom providers working, you can also contribute this to a public oEmbed repository. It contains configuration information (the registry) for oEmbed providers, as YAML files in the providers directory. Once your PR gets merged, it will be listed out in https://oembed.com/providers.json and thus available for all Drupal developers to use with just the core media. Few months back, the YAML for Radiopublic provider (as shown in above example) got merged to the repository and it’s now available for us to use on Drupal. How cool is that?!
See the Drupal.org change record for more details on the oEmbed support and status.
Go to Source