Community Documentation

Making an entity revisionable

Last updated May 11, 2013. Created by mradcliffe on January 18, 2013.
Edited by slawrence10, blackdog, podarok, nedjo. Log in to edit this page.

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

Change Records for Entity API http://drupal.org/list-changes/entity

  • 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:
    <?php
    $entity
    ->is_new_revision = TRUE;
    ?>
  • Also make sure is_new is set to FALSE. Example:
    <?php
    $entity
    ->is_new = FALSE;
    ?>
  • default_revision property must be set on the entity object for the revision being saved to be set as the default revision. Example:
    <?php
    $entity
    ->default_revision = TRUE;
    ?>

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

Page status

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Level
Advanced
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.