Drupal Technical
How to create an custom rule action using hook_rules_action_info?
We can create custom rules programmatically using the function hook_rules_action_info(). hook_rules_action_info() is a useful hook provided by rules API to create custom rules programmatically. We can use our custom functions to perform the actions that we require.
Following is a sample of the hook_rules_action_info implementation:
function abc_custom_rules_action_info() {
return array(
'abc_custom_action' => array(
'label' => t('Custom Action'),
'parameter' => array(
'param1' => array(
'type' => 'int',
'label' => t('Parameter Label'),
),
'param2' => array(
'type' => 'commerce_order',
'label' => t('Parameter Label2'),
),
.
.
.
),
'configurable' => FALSE,
'group' => t('ABC Custom module action'),
'callbacks' => array(
'execute' => 'abc_custom_action',
),
),
);
- label : Label for the rule action, that appears in the Rules interface.
- parameter : Parameter that needs to be passed to the custom action function
- group: A group for this element, used for grouping the actions in the interface.
- callbacks: Array of custom functions that to be used for this action's functioning.
This function has more parameters, but the above are most required ones to create a custom action. For more information about the parameters used, refer this.
If you want to know more about creating custom rule action, please let us know. For further help or assistance, click here.