Making an entity revisionable
Last updated on
15 August 2017
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
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:
$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', // The name of the database table where the entity data is stored. 'base table' => 'my_entity', // The name of the database table where the revisioned entities are stored. // It can be any name you choose, but convention is '[base table]_revision'. 'revision table' => 'my_entity_revision', 'entity keys' => array( // The revision column name. node uses 'vid'. You may name it whatever you // wish. 'revision' => 'vid', ) ... ), ...
For an example, see the entity_test.module and entity_test.install files, which are in the tests directory of the Entity API module.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion