node_submit
- Versions
- 4.6
node_submit(&$node)- 4.7 – 7
node_submit($node)
Accepts a submission of new or changed node content.
Parameters
$node A node array or node object.
Return value
If the node is successfully saved the node ID is returned. If the node is not saved, 0 is returned.
Code
modules/node.module, line 1567
<?php
function node_submit(&$node) {
global $user;
// Fix up the node when required:
$node = node_validate($node);
// If something went wrong, go back to the preview form.
if (form_get_errors()) {
return false;
}
// Prepare the node's body:
if ($node->nid) {
// Check whether the current user has the proper access rights to
// perform this operation:
if (node_access('update', $node)) {
$node->nid = node_save($node);
watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
$msg = t('The %post was updated.', array ('%post' => node_invoke($node, 'node_name')));
}
}
else {
// Check whether the current user has the proper access rights to
// perform this operation:
if (node_access('create', $node)) {
$node->nid = node_save($node);
watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
$msg = t('Your %post was created.', array ('%post' => node_invoke($node, 'node_name')));
}
}
drupal_set_message($msg);
return $node->nid;
}
?>Login or register to post comments 