function _clone_node_prepare in Node clone 7
Prepares a node to be cloned.
3 calls to _clone_node_prepare()
- clone_action_clone in ./
clone.module - Action callback.
- clone_node_prepopulate in ./
clone.pages.inc - Clones a node - prepopulate a node editing form
- clone_node_save in ./
clone.pages.inc - Clones a node by directly saving it.
File
- ./
clone.pages.inc, line 214 - Additional functions for Node_Clone module.
Code
function _clone_node_prepare($original_node, $prefix_title = FALSE, $account = NULL) {
$node = clone $original_node;
if (!isset($account->uid)) {
$account = $GLOBALS['user'];
}
$node->nid = NULL;
$node->vid = NULL;
$node->tnid = NULL;
$node->log = NULL;
// Also handle modules that attach a UUID to the node.
$node->uuid = NULL;
$node->vuuid = NULL;
// Anyonmymous users don't have a name.
// @see: drupal_anonymous_user().
$node->name = isset($account->name) ? $account->name : NULL;
$node->uid = $account->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();
if ($prefix_title) {
$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) {
// Cast to int since that's how they need to be saved to the DB.
$node->{$key} = (int) in_array($key, $node_options);
}
}
return $node;
}