3

I am using D8 and creating revision for a node with the following code.

  $nid = "my_node_id";
  $node = \Drupal\node\Entity\Node::load($nid);
// Make this change a new revision
  $node->setNewRevision(TRUE);
  $node->revision_log = 'Created revision for node' . $nid;
  $node->setRevisionCreationTime(REQUEST_TIME);
  $node->setRevisionUserId($user_id);
  $node->save();

When I create a revision, it is set as the main revision, instead of one of the revisions. Is it taking the revision timestamp when creating, and pushing latest to the top? Is there a function that tells me I am using the latest revision?

0

1 Answer 1

5

You're looking for \Drupal\Core\Entity\RevisionableInterface::isDefaultRevision(), set that to false if you want to save a revision that is not the default revision.

2
  • 2
    Should use it like $node->isDefaultRevision(FALSE); right ?
    – KTM
    Commented May 18, 2017 at 11:45
  • 1
    Yes, exactly like that
    – Berdir
    Commented May 18, 2017 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.