Making an entity revisionable

Last updated on
2 June 2017

Requires entity version 7.x-1.0 or greater
Original issue #996696: Support revisions in Entity API

Change Records for Entity API

  • The revision table for your entity type requires a revision column set to serial type as of entity 7.x-1.0.
  • Any additional properties that will be saved in the revision table can be set on the entity object.
  • is_new_revision property must be set on the entity object for a new record to be written to the revision table. Otherwise it will update the row corresponding to the current revision. Example:
    $entity->is_new_revision = TRUE;
  • default_revision property must be set on the entity object for the revision being saved to be set as the default revision. Example:
    $entity->default_revision = TRUE;
  • Don't forget to tell the entity info that your entity has a revision table, a revision field and an "entity keys" revision.
    If you don't, entities with "is_new" will not create a new revision. Example:.
    function hook_entity_info() {
    'entity keys' => array(
      'id' => 'id',
      'bundle' => 'type',
      'base table' => 'my_entity', // table that stores your entity info
      'revision table' => 'my_entity_revision', // revision table name, can be any name you choose, but convention would be [base table]_revision
      'revision' => 'vid', // Revision column name, node uses 'vid', you can name it what ever you want.
      'entity keys' => array(
          'revision' => 'vid'   

For example check the entity_test.module and entity_test.install files (found within the /test/ directory of the Entity API module).