Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Adding custom oEmbed providers to remote video media source with Drupal 9 & Drupal 8 oEmbed Providers module

Parent Feed: 

One of the ways to engage your visitors is by using various multimedia on your website and Drupal’s Media module provides a fantastic way to achieve that. An additional support was added to the Media module in Drupal 8.6.0 that lets you easily embed third-party videos from an URL into your site’s content called the oEmbed feature.

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!).

oEmbed Providers Module

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.
Media Library

Step 2: Install and Enable the oEmbed Providers module

oEmbed Provider

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.

Custom eEmbed 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.

Add Custom oEmbed ProviderAdd oEmbed Provider

       

     b. Global enable/disable providers

      ▪ The oEmbed Providers module provides an user interface for enabling and disabling providers.

Allowed Provider

   

     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

oEmbed Provider URL

     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.

External Fetch

   

    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.
Add Media

Okay, that’s it! You can now see the videos from your custom provider being rendered on your Drupal site.

Video Testing

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.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web