Configuring media

by Gisle Hannemyr

This chapter is about configuring media.

Table of contents

Drupal core modules discussed in this chapter: CKEditor, Media, Media Library.

Introduction

The core Media module is now part of core. It is disabled by default, but there is nothing to install. It shares no code with the legacy Media project for Drupal 7 and earlier.

The media system consists of two modules:

  1. Media: Represents media assets as Drupa entities. Also a drop-in replacement for the Drupal core image field.
  2. Media Library: Makes media assets reusable and provides a UI.

A Drupal image field is attached to a node. If you want to reuse the image in another node, you'll have to upload it again. In the media system, the image is attached to a media entity, and the node can reference that entity. This media assets reuseable, as they can be referenced from multiple nodes.

media-field.png
In the media system, the image is attached to a media entity, and the node can reference that entity.

Installing the modules

Navigate to Manage » Extend and locate the modules Media and Media Library, check both, and press "Install" at the bottom of the screen.

Now, if you navigate to Manage » Structure there will be an entry for "Media types". They are very similar to content types, and like content types, they have fields. They also have the property "Media source", which stores essential information about the media item, and a field to identify the media source.

This table lists the media types that types exist by default, their media media source property, and the field type for the field used to hold the identifier:

Content typeMedia sourceField type
AudioAudio fileFile
DocumentFileFile
ImageImageImage
Remote videoRemote videoText (plain)
VideoVideo fileFile
Default media types, with media source and field type.

Add a media field to a content type

You add the media field like any other field. Navigate to Manage » Structure » Content types and pick the content type to add a media field to my selecting "Manage fields", followed by "+ Add field". Under "Reference", Select "Media", give it a name, allowed number of values, and media type or types". End up by pressing "Save settings".

If an image field is present, it should be deleted.

To use image styles with Media fields, under "Manage display", select Format "Thumbnail", and all defined image styles are selectable.

Final word

Video tutorials:

Last update: 2022-04-16 [gh].