It would be wonderful if your module can trigger a 'clone' event to the rules module and the drupal own actions instrumenting. For the Rules integration, it would be enough to include the following:
1) create clone.rules.inc with the following content:
// implementation of 'hook_rules_event_info'
// required to let Rules know about a new 'clone node' event
function clone_rules_event_info() {
$items = array(
'node_clone' => array(
'label' => t('After cloning a node'),
'group' => t('Node'),
'variables' => array(
'cloned_node' => array('type' => 'node', 'label' => t('The cloned node')),
'original_node' => array('type' => 'node', 'label' => t('The original node')),
),
),
);
return $items;
}
2) add the following after your node_save($node):
if(module_exists('rules')) {
rules_invoke_event('node_clone', $node, $original_node);
}
It works like a charm for me!
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedCan you create a patch for that?
Comment #2
pwolanin CreditAttribution: pwolanin commentedAlso, the event should probably be "clone_node", not the other way around.
Comment #3
jordan8037310 CreditAttribution: jordan8037310 commentedThis is my first time trying to create a patch. Hope it works! Any constructive criticism on formatting of the patch would be appreciated.
Thanks for the great module!
Edit: Might help if the attached file actually contained something... Going to go through my steps again and upload it.
Comment #4
jordan8037310 CreditAttribution: jordan8037310 commentedUpdating status
Comment #5
jordan8037310 CreditAttribution: jordan8037310 commentedokay let's try this again
Edit: Looks like that worked.
Now I'd like to try to configure a Rules action that will execute the Node_Clone operation programmatically. Any ideas or direction on this?
I'll post progress as I make some more.
Comment #6
tripper54 CreditAttribution: tripper54 commentedPatch applied well and works great! I re-rolled with some small changes in the comments format to conform to coding standards, also removed some whitespace.
Comment #7
arkjoseph CreditAttribution: arkjoseph commentedany chance this can work in D6?
Comment #8
pwolanin CreditAttribution: pwolanin commentedLooks like a pretty simple change
@arkjoseph - I don't know what the rules APi looks like in 6, but it should be something similar if you want to create the patch.
Comment #9
pwolanin CreditAttribution: pwolanin commentedcommitted to 7.x
Comment #10
skyredwangupdate the title to be more specific
Comment #11
pwolanin CreditAttribution: pwolanin commentedclosing is the absence of a 6.x patch