Drupal 8 Programmatically update a node enabling revision with revision log message.

To enable revision and to log revision message on saving a node in drupal 8 we can use setNewRevision() and setRevisionLogMessage(). Find the below code which uses entity save with revision.


$entity_obj = entity_load('node', 7);
$entity_obj->setNewRevision(TRUE); // enabling revision for the entity save.
$entity_obj->setRevisionLogMessage('Our custom message for entity save.'); // Setting the log message for the revision

Find the revision tab on the node page to list all the revisions for that node.

Revisions for Code Expertz   Help Center.png