Making an entity revisionable

Making an entity becomes revisionable is fairly simple, basically you just need to define the entity's revision table and mark the fields to be revisionable.

This page provides an example of how to make an entity revisionable for Drupal 8, using the Content (ContentEntityBase) Entity Foo as example.

Entity Pilot - content staging for Drupal 8


  • Download and extract the module
  • Add the php-encryption library using composer or Composer manager.
    • For composer - from your Drupal installation directory run composer require "defuse/php-encryption:~1.2.
    • For Composer manager, refer to its documentation

Getting started

Creating a content entity type in Drupal 8

This page provides an example of how to create a content entity type, with administration management pages, for Drupal 8.

It will let you know how-to create a 'Contact' entity to add, edit and delete People (Contacts). Entity is fully fieldable and uses most of the new entity concepts available in Drupal 8.


Create a custom content and configuration entity

This explains how to create a node-like entity in Drupal 8. That means that we'll create one configuration entity(FooType) which will serve as type or bundle for our second entity(Foo) which is a content entity and will represent the node itself. The content entity will also support revisions and translations(not yet tested).

2015-04-29 WARNING: This page is more than "needs updating" : most of its content is obsolete, since entity definitions are now provided using annotations-based plugins, the schema is no longer created manually using hook_schema(), permissions are now defined in <module>.permissions.yml, some global scope functions in the examples have been removed, and the <module>.routing.yml format has changed a bit too.

Working with the Entity API

This covers the generic entity API, configuration entity and content entity specific API's will be covered in specific chapters. TODO: Link once created.


// Make sure that an object is an entity.
if ($object instanceof \Drupal\Core\Entity\EntityInterface) {

// Make sure it's a content entity.
if ($entity instanceof \Drupal\Core\Entity\ContentEntityInterface) {

// Get the entity type.

// Make sure it's a node.
if ($entity instanceof \Drupal\node\NodeInterface) {

// Using entityType() works better when the needed entity type is dynamic.
$needed_type = 'node';
if ($entity->entityType() == $needed_type) {

Get information from an entity/ Entity methods

A number of generic methods are available to get information from an entity, like the ID, bundle, revision ID and so on. See the documentation on the EntityInterface for details.

// Get the ID.

// Get the bundle.

// Check if the entity is new.

// Get the label of an entity. Replacement for entity_label().

// Get the URI for an entity.
// n@todo: This might still change with the new URI template API.

Entity API - Drupal 8

For the Drupal 7 Entity API: Go here.


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.


Subscribe with RSS Subscribe to RSS - entity api