By berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
The default Entity and DatabaseStorageController now support saving and deleting entity revisions.
To support this, a number of new methods have been added.
-
EntityStorageControllerInterface::deleteRevision($revision_id)
Deletes a specific revision. There is also a wrapper function calledentity_revision_delete($entity_type, $revision_id) - EntityInterface::setNewRevision($value = TRUE)
Allows to set that an entity should be saved as a new revision. Replaces the node specificrevisionproperty. - EntityInterface::isNewRevision()
Corresponding function that returns TRUE if an entity should be saved as a revision. Usually only used by storage controllers and is reset after the revision was saved, just likeEntityInterface::isNew(). To check if an entity was saved as a new revision inhook_entity_update(), compare the revision ids:$entity->getRevisionId() != $entity->original->getRevisionId(). - The entity class can implement EntityInterface::preSaveRevision(EntityStorageControllerInterface $storage_controller, \stdClass $record) to change the revision record that is going to be saved.
Store a new as a new revision in 7.x
$node->revision = TRUE;
node_save($node);
8.x
$node->setNewRevision();
$node->save();
// Load a revision.
$node = \Drupal::entityTypeManager()->getStorage('node')->loadRevision(1);
// Delete a revision.
$node = \Drupal::entityTypeManager()->getStorage('node')->deleteRevision(1);
Impacts:
Module developers