I have developed a solution that works for us, based on Berdir's advice. My biggest trouble was improper implementation of hooks. I didn't know that in D8 hooks must (still) go into the .module file. Here's what we do to patch nodes via a rest route and force new revisions.
Patch via rest like this:
function patchNode(csrfToken, id, package) {
$.ajax({
url: 'http://example.com/cms/node/' + id + '?_format=hal_json',
method: "PATCH",
data: JSON.stringify(package),
headers: {
"X-CSRF-Token": csrfToken,
"Accept": "application/hal+json",
"Content-Type": "application/hal+json"
},
success: function(data, status, xhr) {
console.log('patchNode successful.')
}
});
}
Create a module to implement setNewRevision via hook_node_presave. Hooks should go in to the .module file for your module.
<?php
/**
*
* @file
* Force Revisions
*
* creates a new revision of a node on every save event
*
*/
use Drupal\Core\Entity;
use Drupal\node\Entity\Node;
use Drupal\Core\Entity\EntityInterface;
function force_revisions_node_presave(EntityInterface $node) {
$node->setNewRevision(TRUE);
}