clone.rules.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file Node clone rules functions
  4. */
  5. /**
  6. * Implementation of hook_rules_event_info.
  7. */
  8. function clone_rules_event_info() {
  9. // Let rules know about the node clone event.
  10. $items = array(
  11. 'clone_node' => array(
  12. 'label' => t('After cloning a node'),
  13. 'group' => t('Node'),
  14. 'variables' => array(
  15. 'cloned_node' => array('type' => 'node', 'label' => t('The cloned node')),
  16. 'original_node' => array('type' => 'node', 'label' => t('The original node')),
  17. ),
  18. ),
  19. );
  20. return $items;
  21. }
  22. /**
  23. * Implements hook_rules_action_info().
  24. */
  25. function clone_rules_action_info() {
  26. $actions = array(
  27. 'clone_action_node_clone' => array(
  28. 'label' => t('Clone a node'),
  29. 'group' => t('Node'),
  30. 'parameter' => array(
  31. 'node' => array(
  32. 'type' => 'node',
  33. 'label' => t('Node to clone'),
  34. ),
  35. ),
  36. 'provides' => array(
  37. 'clone' => array(
  38. 'type' => 'node',
  39. 'label' => t('Cloned node'),
  40. ),
  41. ),
  42. ),
  43. );
  44. return $actions;
  45. }
  46. /**
  47. * Action callback for cloning a node.
  48. * @param $node
  49. * The node to clone.
  50. */
  51. function clone_action_node_clone($node) {
  52. include_once drupal_get_path('module', 'clone') . '/clone.pages.inc';
  53. $new_nid = clone_node_save($node->nid);
  54. $new_node = entity_load_single('node', $new_nid);
  55. return array(
  56. 'clone' => $new_node,
  57. );
  58. }