I have successfully started using Triggered Rules. Most of my actions involve using "Execute custom PHP code".
Now that I've got things up & running I'd like to move these custom php actions into a custom module.
I'm having trouble!
For example an existing rule (simplified from my real use case) looks like this:
Event:
- After saving new content (conditional on type)
Actions:
- Load a CCK referenced node
- Custom php (for example):
$referenced_node->field_counter['0']['value']++;
// increment simple counter in referenced node
- Save the referenced node
This works great. And is easy using the "Execute custom PHP code" action as the loaded referenced node is available to me as $referenced_node.
Now I want to make a custom module.
- Can I simply use my custom action in place of the "Execute custom PHP code" action in my existing triggered rule?
- In other words can I still use the Rules actions that load and save the referenced node?
- If so, how do I then pass that referenced node into my custom action function to make changes to it?
- Or do I have to load and save the referenced node within my custom action?
my skeleton mymodule.rules.inc looks like this:
/**
* Implementation of hook_rules_action_info().
*/
function mymodule_rules_action_info() {
return array(
'mymodule_action_update_counter' => array(
'label' => t('Update Counter'),
'module' => 'MyModule',
),
);
}
/**
* Action:
*/
function mymodule_action_update_counter() {
$referenced_node->field_counter['0']['value']++;
}
Any help greatly appreciated.
Thanks!