1 node.module | node_object_prepare(Node $node) |
Prepares a node entity for editing.
Fills in a few default values, and then invokes hook_prepare() on the node type module, and hook_node_prepare() on all modules.
Parameters
Node $node: A node object.
File
- core/
modules/ node/ node.module, line 913 - The core module that allows content to be submitted to the site.
Code
function node_object_prepare(Node $node) {
// Check if we can retrieve a node from the tempstore.
$node_tempstore_id = node_build_tempstore_id($node->type);
// Set up default values, if required.
$node_type = node_type_get_type($node->type);
// If this is a new node, fill in the default values.
if (!isset($node->nid) || isset($node->is_new)) {
if (!isset($node->status)) {
$node->status = (int) $node_type->settings['status_default'];
}
if (!isset($node->promote)) {
$node->promote = (int) ($node_type->settings['promote_enabled']) ? $node_type->settings['promote_default'] : 0;
}
if (!isset($node->sticky)) {
$node->sticky = (int) ($node_type->settings['sticky_enabled']) ? $node_type->settings['sticky_default'] : 0;
}
global $user;
$node->uid = $user->uid;
$node->created = REQUEST_TIME;
}
else {
$node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O');
// Remove the log message from the original node entity.
$node->log = NULL;
}
// Always use the default revision setting.
$node->revision = $node_type->settings['revision_enabled'] ? $node_type->settings['revision_default'] : FALSE;
node_invoke($node, 'prepare');
module_invoke_all('node_prepare', $node);
}