Prepares a node for saving by populating the author and creation date.
\Drupal\Core\Entity\EntityInterface $node: A node object.
Drupal\node\Node An updated node object.
function node_submit(EntityInterface $node) {
global $user;
// A user might assign the node author by entering a user name in the node
// form, which we then need to translate to a user ID.
if (isset($node->name)) {
if ($account = user_load_by_name($node->name)) {
$node->uid = $account->uid;
}
else {
$node->uid = 0;
}
}
// If a new revision is created, save the current user as revision author.
if ($node
->isNewRevision()) {
$node->revision_uid = $user->uid;
$node->revision_timestamp = REQUEST_TIME;
}
$node->created = !empty($node->date) && $node->date instanceof DrupalDateTime ? $node->date
->getTimestamp() : REQUEST_TIME;
$node->validated = TRUE;
return $node;
}