You are here

function rb_misc_action_node_clone in Rules Bonus Pack 7

The 'rb_misc_action_node_clone' action.

File

./rb_misc.rules.inc, line 699
Miscellaneous conditions and actions for Rules.

Code

function rb_misc_action_node_clone($node) {
  $cloned_node = clone $node;

  // Reset a few basic values for the clone.
  $properties_to_reset = array();

  // Let any other modules make changes to the array of properties to reset.
  // (This is done by implementing hook_rb_misc_clone_reset_properties_alter.)
  drupal_alter('rb_misc_node_clone_reset_properties', $properties_to_reset);
  foreach ($properties_to_reset as &$property) {
    if (isset($cloned_node->{$property})) {
      $cloned_node->{$property} = NULL;
    }
  }

  // Remove the lingering reference to the foreach-by-reference above.
  unset($property);

  // Add an extra property as a flag.
  $cloned_node->clone_from_original_nid = $node->nid;

  // Set the cloned node as new.
  $cloned_node->is_new = TRUE;
  return array(
    'cloned_node' => $cloned_node,
  );
}