I am modifying the node content on hook_form_alter()
as follows.
$node = \Drupal\node\Entity\Node::load($nid);
if ($node) {
$node->field_p_frontip = $availableip[0];
$node->save();
}
I need to clone the node and save it in the hook_form_alter()
submission. How could I do this?
UPDATE
In D6 the node was cloned using the function clone_node_save which uses the node id to clone as clone_node_save($nid,false);
, what is the corresponding function in D8 ??
EntityInterface::createDuplicate()
. So in the case of your node object:$cloned_node = $node->createDuplicate()
. Calling$cloned_node->save()
will save a new node with a different ID.