One of the best things about CMSs is they can lessen the human efforts by a huge margin but, even then adding any media is never easy. At least it wasn’t until Media handling modules came into action, let us discuss how it made things easy. To understand about Media Entity, we need to understand the Media modules as a whole and why they exist. Let us go into the days of Drupal 7 when there was no editor nor media management tool out-of-the-box. Hey, have no fear modules are here, today.
We used to have WYSIWYG editor and CKEditor modules, which are great. But even with these handling media meant to copy-paste the HTML. This is where the Media module came into action. A very popular module in Drupal 7, handling media is easy. This module provided decent functionality but it’s a bit buggy with CKEditor. Today, there are other great media handling modules like SCALD and IMCE to handle the situation.
Media Handling in Drupal 8
In Drupal 8 the media module is re-architected into smaller components. A lot of people, contributors of Media module, SCALD got together and rolled up their sleeves to build a proper media management system.
Simply put, now the media module in Drupal 8 is a collection of configurations. They breached Media module into 3 modules, which are:
- Media Entity: It is used to store asset’s, it doesn’t do much work it just offers a base entity. If you want to handle Image, Audio, YouTube video etc. You have to download the provider modules. If you failed to comprehend this, worry not we’ll go through this later in the article.
-
Entity Embed: It is used to embed any type of entity content types, users, media entities etc. into the text area. The best part about it is, it is not limited only to the media entities. When you try to embed an entity, it adds a tag to HTML which looks something like this
<drupal-entity data-embed-button =” media” …
After the tags are added the module has a filter that searches for this tag and replaces them with a rendered entity. -
Entity Browser: It allows you to create a browser where you are allowed to browse through media assets, select them and embed them. We can use entity browser with other modules like inline entity form, Dropzone JS (we use drag and drop functionality to add media) etc.
Installing And Using Media Entity
To get a clear understanding let us install Media Entity, and we’ll use video embed media to add a video to see how it works and to get a solid grip on provider modules.
Install and enable Media Entity and Media embed field, open command prompt or terminal and use the Drush command:
drush en media_entity, video_embed_media -y
Go to Structure --> Select Media Bundles. rebuild the cache before proceeding.
drush cache-rebuild -y
or
drush cr
Creating A Media Bundle
Give a Label to the media bundle and description.
Aha! now the selection of Provider module here you should select the Media Provider Module as said above, Media Entity uses these modules, since we installed the video embed media module we’ll see it in the drop down of the type provider, select it.
Side note: When you select it, you’ll see a box saying “ A video embed field will be created on this media bundle when you save this form”, if you are curious as of what it is, the media bundle don’t hold the video a field holds the path of the video which will be later rendered.
Click on Save media bundle.
Go to Content > Media > Click on Add media > Select Image.
If you didn’t see the Media tab rebuild the cache.
Click on Video ( It’s the label you assigned to the bundle). Give the media a name, URL of the video and Click Save and Publish.
Yay! video of my favorite TV show is published, so should your video.
Now you can add media in Drupal with ease, select from the myriad of media provider modules to insert the asset you wish to. It’s not limited to a video nor an image, check out all the other provider modules to use them on your website. Modules are the best part of Drupal!
Subscribe
Related Blogs
SDC: Integrating Storybook & Single Directory Component
Today, we will talk about about Drupal Single Directory Components or SDC and Storybook. Single Directory Components in Drupal allows you…
RFP: How To Create An RFP For Open Source Solutions?
A good Request for Proposals (RFP) or Call for Proposals (CFP) clearly states the goals and expectations of your project and sets the…
Drupal 7 End Of Life: Top Reasons You Should Migrate To Drupal 10
Drupal 10 was released in December 2022 and ever since, the community has been pushing its users to do Drupal 7 to 10 migration. As per…