You are here

function _node_clone_node_prepare in Node clone 8

Prepares a node to be cloned.

3 calls to _node_clone_node_prepare()
node_clone_action_clone in ./node_clone.module
Action callback.
node_clone_node_prepopulate in ./node_clone.pages.inc
Clones a node - prepopulate a node editing form
node_clone_node_save in ./node_clone.pages.inc
Clones a node by directly saving it.

File

./node_clone.pages.inc, line 235
Additional functions for Node_Clone module.

Code

function _node_clone_node_prepare($original_node, $prefix_title = FALSE, $account = NULL) {
  $node = clone $original_node;
  if (!isset($account->uid)) {
    $account = \Drupal::currentUser();
  }
  $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 = node_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;

  // @FIXME
  // // @FIXME
  // // The correct configuration object could not be determined. You'll need to
  // // rewrite this call manually.
  // if (variable_get('node_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;
}