Development

Variable Types for Use in hook_rules_event_info()

There is plenty of documentation out there explaining how to create custom rules events. What I had a tough time finding was a list of the variable types that are available for elements reacting on this event. I had seen examples of “text” and “user” but I really wanted to know what all of the types are.

Before I go on, here’s an example of what I’m talking about (line 12; “lead” is an entity type on my site):

The API states, regarding the variable type property:

type: The rules data type of the variable. All types declared in hook_rules_data_info() or supported by hook_entity_property_info() may be specified.

So, to get a list of the possible variable types you can use in your events, simply invoke (and inspect the output of) the two functions. Here’s how I did it (via devel’s “Execute PHP Code” page):

Here’s a small sample of the results I received when I ran this on my current project:

img20150317173829

 

If you wanted to sort the results, you could tweak it a bit:

Lastly, a quick note about entities. If you pass “node” as the variable type (or any entity type), you can also want to pass along the bundle (e.g., “blog”). These are listed in the output of the commands demonstrated above, so don’t hesitate to expand any of the variables in the dpm() output. The bundle property is documented in the API, which states:

bundle: (optional) If the type is an entity type, the bundle of the entity.

Leave a Reply

Your email address will not be published.