I have a node
object and I need to create revisions for that node programmatically. When I tried as follows it's not working. Instead it's creating new nodes. What am I doing wrong? How can I fix this?
$node = Node::create([
'nid' => $nid, // My desired node ID for the revision.
'type' => $bundle_type,
'field1' => $value1,
'field2' => $value2,
]);
$node->revision = TRUE;
$node->save();
$node->setPublished(true);
$nid = $node->id();
print 'Created revision for node' . $nid;