Entity API

This guide includes best practices and documentation for working with entities in Drupal.

Drupal 7 core has the following functions in files:

These functions provide limited functionality for Entity usage. However, developers who want to develop using the Entity concept usually utilize the contributed module Entity API.

An Introduction to Entities

If you are looking for the documentation or the entity API in Drupal 8, click here.

Entity API Tutorial

This is the developer documentation for the Entity API module. Also check the README.

Entity Token Support

Drupal 7

Providing a new entity type

The Entity CRUD API allows you to easily create a new entity type. You'll get full Create, Read, Update, Delete and Index (CRUDI) functions,

Make an entity type exportable

If your entity could be considered as site configuration, it is usually a good idea to make it exportable.

Making an entity revisionable

Requires entity version 7.x-1.0 or greater

Enabling Revisions on a Table With Existing Data


Viewing entities

The entity API assists in writing the code for viewing an entity by providing entity_build_content() and entity_view() functions which take

Module integration helpers

The entity API provides some useful defaults for integrating with Rules and for providing Entity property information. If your entity type

i18n module integration

There is a i18n controller for integration (exportable) entities with the i18n module. However, the controller requires some additional code

Making use of the admin UI

Optionally, the entity API helps provide an administrative interface for managing entities, e.g. the UI for managing profile types of the

Documentation template for provided hooks

The Entity API implements hooks for any entity types implemented with the provided controller. To make developers aware of this hooks, it's

Basic file skeleton + CRUD hooks

Values to replace:

View-related hooks.

If your module makes use of entity_view(), add the following view-related hooks:

Additional hooks for exportable entities

Values to replace:

Misc hooks

If your module implements an entity form with the help of entity_ui_get_form(), the following template helps you documenting the according

Providing metadata for additional entity types

In case your module is providing an additional entity type, but is not making use of the Entity CRUD API (as described previously) some

Views integration

Entity API tries to generate suitable Views integration for the entity based upon:

Entity property information

For a general introduction of metadata about entity properties and its purpose, check this blog post.

Data types

These are the data types to be used for describing entity properties:

Entity metadata wrappers

Table of contents

Property info for fields

Fields are added in automatically by the Entity API module, as long as the field type is supported. However, the module providing the field

Displaying properties when viewing entities

When an entity is viewed, the EntityAPIController calls the buildContent() method to assemble the entity information, entity's field data