Site Building

How to Add Fields to a Media Type in Drupal for Drupal 8, 9, and 10

Drupal media entities are fieldable entities, which means that you can add any custom fields you want to your Media types. These fields can be used for collecting additional metadata about a resource, categorizing and organizing resources so they're easier to find in a large media library, or for displaying information like a photo credit or transcript for a video. The possibilities are endless once you know how to add, and optionally display, fields in Drupal.

Some example use cases for adding fields to Media types:

  • Collect, and display, a credit to go along with a photo. This could also be a date, a location, or any other metadata.
  • Store resource width and height dimensions as custom fields so they can be referenced by display logic in the theme layer.
  • Use Taxonomy reference fields to add tags or categories to help keep a large library organized.

In this tutorial we'll:

  • Learn how to add fields to a Media type
  • Verify our new custom field is working

By the end of this tutorial you'll know how to add custom fields to any Media type.