I want to use Rules UI to define some action sets, but want to execute those actions programmatically from a custom module.

How to I execute the action by code and pass the needed arguments (just a node in this case).

Thanks!

link|improve this question
feedback

1 Answer

up vote 4 down vote accepted

If you have set it up as a rules component, you can use rules_invoke_component, alternative you can invoke an event, which could trigger mutiple rules by using rules_invoke_event.

Both a similar in that you pass first an name/id and the rest of the args is passed along, so something like

 rules_invoke_component('name', $node);

is properly how you need to do it. This again depends on how the rule/component is defined/configured.

link|improve this answer
Thanks, that was exactly the function I was looking for. I had to pass the argument directly, though - probably because I just have one arg configured in the component. rules_invoke_component('rules_mycomponent', $node); – valderama May 17 '11 at 15:03
@valderama, great I updated my answer in case others need the same info. – googletorp May 17 '11 at 15:17
Does this work for drupal 6? – landing Jan 14 at 9:10
@landing Rules have changed a lot from 6 to 7, but rules_invoke_event exists in 6 rules_invoke_component does not, but I don't believe rules in 6 has the concept of components. – googletorp Jan 14 at 9:25
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.