Community

SOLVED: Rules 2: Getting data back from rules_invoke_event()?

After calling rules_invoke_event(), how do I get data back from it?

Say that I had an event called 'pre_dive' that I invoke just before bringing up the Dive form.

I'd like to be able to have an 'abort_dive' action. If the user sets up a rule with a 'pre_dive' event trigger that ends up using the 'abort_dive' action, I want the calling function to know, so it redirects somewhere else, and never brings up the Dive form.

What's the best way to do this? rules_invoke_event() doesn't have a return value and doesn't pass variables by reference.

Comments

The direct answer is: Set up

The direct answer is:

Set up a Rules (or Entity) data type for an object to pass into the action function. Objects are always passed by reference. Any changes to the object can be picked by the function that called rules_invoke_event().

A better answer is:

Don't pass data out for this use case. Just invoke the event. If a rule wants to abort whatever the calling function is doing, it can use a page redirect action to do that, probably also with an additional action to display a message on the site.

--
www.ztwistbooks.com. Math books that are actually fun.