[Drupal] How to create a custom rule action using hook_rules_action_info in Drupal7?

| | 1 min read

Rules are very important and most common using thing in Drupal. We can create custom rules programmatically using the hook_rules_action_info. There is a useful hook hook_rules_action_info() provided by rules api to create custom rules programmatically. Using this 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 sample_custom_rules_action_info() {
  return array(
    'sample_custom_action' => array(
      'label' => t('Custom Rule Action'),
      'parameter' => array(
        'param1' => array(
          'type' => 'int',
          'label' => t('Sample Label'),
        ),
        'param2' => array(
          'type' => 'commerce_order',
          'label' => t('Sample Label2'),
        ),
      ),
      'configurable' => FALSE,
      'group' => t('sample Custom module action'),
      'callbacks' => array(
        'execute' => 'sample_custom_action',
      ),
    ),
  );

0l>

  • Label for the rule action appears in the Rules interface.
  • Parameter that needs to be passed to the custom action function
  • A group for this element, used for grouping the actions in the interface.
  • callbacks are 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.

    You may also look into other solved issues related to Drupal rules configurations here.

    For more information about the parameters used, refer: Drupal. Please let us know if we can help you with any further Drupal rules configurations.