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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/** * Implementation of hook_rules_event_info(). * @ingroup rules */ function mymodule_rules_event_info() { $info = array(); $info['mymodule_lead_success'] = array( 'label' => t('The lead has been sent successfully'), 'group' => t('Leads logging'), 'variables' => array( 'lead' => array( 'type' => 'lead', 'label' => t('The lead entity') ), ), ); return $info; } |
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):
1 |
dpm(array_merge(module_invoke_all('rules_data_info'), module_invoke_all('entity_property_info'))); |
Here’s a small sample of the results I received when I ran this on my current project:
If you wanted to sort the results, you could tweak it a bit:
1 2 3 |
$types = array_merge(module_invoke_all('rules_data_info'), module_invoke_all('entity_property_info')); ksort($types); dpm($types); |
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.