Problem/Motivation
Initial issue text:
For Drupal 8 to support "forward revisions" it must declare during node_save whether the given node object is meant to go in the node table or not. Agentrickard has started a patch to this end at #218755-106: Support revisions in different states
The addition of the is_live property means that many modules implementing hook_node_update() will have to check that the given revision is going live.
For instance, the path module should not change the alias for node/123 if the revision of 123 being saved is not going to the node table.
This patch is a start. There are UI implications to this change. With this patch, data entered in the URL alias field is discarded if the revision isn't going live.
Finally I think this patch will fail testing as it does not include the is_live property from #218755-106: Support revisions in different states and some tests will have to be modified/added to deal with is_live anyway.
Current situation:
The idea is not to save URL aliases or execute certain procedures if the node being processed is not the default revision, previous patches (mentioned above) have already fixed some of these cases, but as mentioned below by berdir, the only bit here that's not addressed yet is search, which is in \Drupal\node\Entity\Node::postSave()
now, there are also node_comment hooks that update the search index. This MR addresses these cases
Steps to reproduce
- You can use drush eval
, load a previous revision of the node:
$node = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($revision_id);
and then try to run
node_reindex_node_search($node->id())
This shouldn't run because this is allowing an old version of the node to be re-indexed.
Proposed resolution
Use the entity method isDefaultRevision()
to check if current entity is default (latest) revision before calling the search_reindex function, for example
/core/modules/node/src/Entity/Node.php
postSave(EntityStorageInterface $storage, $update = TRUE) {
\Drupal::service('node.grant_storage')->write($this, $grants, NULL, $update);
}
// Reindex the node when it is updated, but only if its the default revision. The node is automatically indexed
// when it is added, simply by being added to the node table.
if ($update && $this->isDefaultRevision()) {
node_reindex_node_search($this->id());
}
}