Warning message

Documentation is currently being migrated into the new system. Some pages might be temporarily missing, and some guides might appear empty. Thank you for your patience while we are improving Drupal.org documentation.

Introduction to Entity API in Drupal 8

Last updated on
October 13, 2016 - 16:37

For the Drupal 7 Entity API: Go here.

Background

The Entity System was introduced late in the Drupal 7 development cycle with basic standards for how entities were loaded. The contributed entity.module expanded the API further by adding support for saving and deleting entities and many other improvements.

The majority of those improvements are now included in Drupal 8. Entity validation is now in its own API (which could validate an Entity saved via REST, rather than a form, for example).

The Drupal 8 entity system

Entities are typed classes with methods
Generic methods $entity->id()
Entity type specific methods $node->getTitle()

Both types are defined and documented in interfaces.

Handlers

Entities are supported by handlers.

Storage handler - Supports loading, saving and deleting entities. This includes default support for revisions, translations and configurable fields.

Additionally, there are other handlers such as for access control, viewing, listings and forms.

Two variants

Entity types in core comes in two variants.

Configuration Entity
Used by the Configuration System. Supports translations and can provide custom defaults for installations.
Content Entity
Consist of configurable and base fields, can have revisions and support translations.

This page is still a stub, documentation is being written while the Entity API is finalized for Drupal 8.

TODO/Planned:
- Handlers
- - Storage
- - Access
- - Forms
- - View Builder
- - List
- Bundles
- Configuration entities
- Content entities
- - Revisions
- - Translations
- - Fields
- UUID support
- Entity query
- Routing

Drupal 8 Entity API issues being worked on: