Module Development

Expose Custom Entities to Views for Drupal 8, 9, and 10

Drupal's Entity API allows developers to expose custom entities to the Views module, and takes care of many common features. It can handle exposing the fields associated with fieldable entity types for use as fields, filters, sorts, and arguments. It provides a way to customize any aspect of the Views integration, and makes it possible to create explicit relationships between 2 different entity types.

In this tutorial we'll:

  • Expose a custom Subscriber content entity type and all of its data to Views.
  • Create an explicit relationship between the custom content entity and Drupal core User entities.
  • Build a view of Subscriber entities.

By the end of this tutorial you should know how to expose custom entities to Views.