23

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!

26

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 is similar in that you pass first a name/id and the rest of the args is passed along, so something like

 rules_invoke_component('name', $node);

if your custom component rule has several parameters pass them one by one and separate them with comma as example

rules_invoke_component('rules_save_search_send_activation_sms',  'paramval1', 'paramval2', ....);

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

  • 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? – user2014 Jan 14 '12 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 '12 at 9:25
  • if you have custom rule compoent ,pass parameters one by one and separate them with comma example rules_invoke_component('rules_save_search_send_activation_sms', 'test ', '93333333333'); – Yusef Mohamadi Aug 6 '15 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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