function clone_node_save in Node clone 6
Same name and namespace in other branches
- 7 clone.pages.inc \clone_node_save()
Clones a node by directly saving it.
2 calls to clone_node_save()
- clone_node_check in ./
clone.pages.inc - Menu callback: prompt the user to confirm the operation
- clone_node_confirm_submit in ./
clone.pages.inc - Handle confirm form submission
File
- ./
clone.pages.inc, line 190 - Additional functions for Node_Clone module.
Code
function clone_node_save($nid) {
if (is_numeric($nid)) {
global $user;
$node = node_load($nid);
if (isset($node->nid) && clone_is_permitted($node->type)) {
$original_node = drupal_clone($node);
$node->nid = NULL;
$node->vid = NULL;
$node->tnid = NULL;
// Anyonmymous users don't have a name.
// @see: drupal_anonymous_user().
$node->name = isset($user->name) ? $user->name : NULL;
$node->uid = $user->uid;
$node->created = NULL;
$node->menu = clone_node_clone_menu_link($original_node);
if (isset($node->book['mlid'])) {
$node->book['mlid'] = NULL;
$node->book['has_children'] = 0;
}
$node->path = NULL;
$node->files = array();
$node->title = t('Clone of !title', array(
'!title' => $node->title,
));
// Add an extra property as a flag.
$node->clone_from_original_nid = $original_node->nid;
if (variable_get('clone_reset_' . $node->type, FALSE)) {
$node_options = variable_get('node_options_' . $node->type, array(
'status',
'promote',
));
// Fill in the default values.
foreach (array(
'status',
'moderate',
'promote',
'sticky',
'revision',
) as $key) {
$node->{$key} = in_array($key, $node_options);
}
}
// Let other modules do special fixing up.
drupal_alter("clone_node", $node, $original_node, "save-edit");
node_save($node);
return $node->nid;
}
}
}