1 node.module | node_submit($node) |
Prepares a node for saving by populating the author and creation date.
File
- core/
modules/ node/ node.module, line 1011 - The core module that allows content to be submitted to the site.
Code
function node_submit($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 (!empty($node->revision)) {
$node->revision_uid = $user->uid;
}
// Convert the date into a timestamp.
if (isset($node->date) && is_array($node->date)) {
$node->date = $node->date['date'] . ' ' . $node->date['time'];
}
$date = new BackdropDateTime(!empty($node->date) && is_string($node->date) ? $node->date : 'now');
$node->created = $date->format('U');
$node->validated = TRUE;
return $node;
}