You are here

function clone_nodeapi in Node clone 6

Implementation of hook_nodeapi().

File

./clone.module, line 139
Allow users to make a copy of an item of content (a node) and then edit that copy.

Code

function clone_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  // Handle the core bugginess in node_object_prepare() that overwrites the
  // publishing options.
  if ($op == 'prepare' && isset($node->clone_from_original_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);
      }
    }
    else {
      $original_node = node_load($node->clone_from_original_nid);
      foreach (array(
        'status',
        'moderate',
        'promote',
        'sticky',
        'revision',
      ) as $key) {
        $node->{$key} = isset($original_node->{$key}) ? $original_node->{$key} : NULL;
      }
    }
  }
}