Creating a Media Paragraph Type

Goal

In this unit you'll create and use a new Media Paragraph Type so editors can select one or more previously uploaded images from the Media Library, and add them to their content.

Refresher: Media

The Media module, part of Drupal Core, lets you upload, manage, and reuse media items such as images, documents, audio, and video files:

Media is part of Drupal Core, but is not automatically enabled on new sites.

Once enabled, new media-related features become available, such as:

  • Media Types (similar to Content Types).
  • A Media upload field.
  • A Media Library.

Image Field vs. Media Field

Whether you use an Image field or a Media field set to only allow media of the type 'image', the end result is the same: editors can use that field to add images to their content.

However, Image fields only let you upload an image to a node, but offer no other functionality. If you want to use the same image on a different node, you have to upload the image again.

Media fields let you choose between uploading a new image, or reusing a previously uploaded image via the Media Library.

There are many more advantages to using Media fields over Image fields, but going deeper into the Media system is outside of the scope of this unit.

Activity 1

  • Enable the Media module.
  • Enable the Media Library module.
Hide hints
show hints

Activity 2

  • Create a Paragraph Type named 'Media image' that contains a media field. The media field should be restricted to only allowing media of the type 'image'.
  • If everything went well, editors now have the choice between using your Image Paragraph Type or your Media image Paragraph Type.
Hide hints
show hints

Activity 3

  • Create a new article and use both of your image-related paragraph types.
  • Compare your experience using the Image and Media Image Paragraph Types. Do you have a preference? Do you think your editors will have a preference?
  • Your Media fields have more features than Image fields and seem more useful. Can you think of a reason to still use an Image field instead of a Media field?
Hide hints
show hints

Summary

  • Which exact field types you use in your Paragraph Types depends on the functionality you want to offer to your editors.
  • Image fields let you upload images but don't let support reuse of previously uploaded images.
  • Media fields give you a choice between uploading a new image or reusing a previously uploaded image, selected from the Media Library.