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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev

Can you create a patch for that?

pwolanin’s picture

Also, the event should probably be "clone_node", not the other way around.

jordan8037310’s picture

Status: Needs review » Active
FileSize
0 bytes

This 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.

jordan8037310’s picture

Assigned: Unassigned » jordan8037310
Status: Active » Needs review

Updating status

jordan8037310’s picture

Status: Active » Needs review
FileSize
1.05 KB

okay 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.

tripper54’s picture

Patch 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.

arkjoseph’s picture

any chance this can work in D6?

pwolanin’s picture

Looks 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.

pwolanin’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

committed to 7.x

skyredwang’s picture

Title: add Rules integration for node clone » add Rules integration (event) for node clone

update the title to be more specific

pwolanin’s picture

Issue summary: View changes
Status: Patch (to be ported) » Closed (won't fix)

closing is the absence of a 6.x patch

  • Commit f41f777 on 7.x-1.x, 8.x-1.x by pwolanin:
    Issue #1720330 by jordan8037310, tripper54: add Rules integration for...