You are here

function hook_rules_action_info in Rules 6

Same name and namespace in other branches
  1. 7.2 rules.api.php \hook_rules_action_info()

Define rules compatible actions.

This hook is required in order to add a new rules action. It should be placed into the file MODULENAME.rules.inc.

Return value

An array of information about the module's provided rules actions. The array contains a sub-array for each action, with the action name as the key.

Possible attributes for each sub-array are:

  • 'label' The label of the action. Start capitalized. Required.
  • 'module' The providing module's user readable name. Used for grouping the actions in the interface. Should start with a capital letter. Required.
  • 'arguments' An array describing the arguments needed by the action with the argument's name as key. Optional. Each argument has to be described by a sub-array with possible attributes as described afterwards.
  • 'new variables' An array describing the new variables the action adds to the rules evaluation state with the variable name as key. Optional. Each variable has to be described by a sub-array with possible attributes as described afterwards.
  • 'eval input' Optional; An array containing form element names of elements contained in the actions settings form ($form['settings']) to which input evaluators should be attached. For settings in a nested array the array keys may be separated by '|' in the name.
  • 'label callback' A callback to improve the action's label once it has been configured. Optional (Defaults to {ACTION_NAME}_label). @see rules_action_callback_label().
  • 'base' The base for action implementation callbacks to use instead of the action's name. This is useful for having a single implementation for a couple of (probably somehow similar) actions. Optional (defaults to the name).
  • 'help' A help text to assist the user during action configuration. Optional. As an alternative one can implement rules_action_callback_help().

Each 'arguments' array may contain the following properties:

  • 'label' The label of the argument. Start capitalized. Required.
  • 'type' The rules data type of the variable, which is to be passed to the action. See http://drupal.org/node/298633 for a list of known types. Required.
  • 'description' If necessary, further description of the argument. The usage of this attribute depends on the data type. Optional.
  • 'default value' The value to pass to the action, when there is no specified value. Optional. It's main usage is in conjunction with the data type 'value' to pass some information from this hook to an actions base implementation.

Each 'new variables' array may contain the following properties:

  • 'label' The default label of the new variable. Start capitalized. Required.
  • 'type' The rules data type of the variable. See http://drupal.org/node/298633 for a list of known types. Required.
  • 'save' If this is set to TRUE, the new variable is saved by rules when the rules evaluation ends. Only possible for data types marked as 'savable'. Optional (defaults to FALSE).
  • 'label callback' A callback to improve the variables label using the action's configuration settings. Optional.

The module has to provide an implementation for each action, for which the function name has to equal the action's name or if specified, the action's base attribute. The other callbacks are optional.

@see rules_action_callback(), rules_action_callback_form(), rules_action_callback_validate(), rules_action_callback_submit(), rules_action_callback_help().

Related topics

11 functions implement hook_rules_action_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_rules_action_info in rules/modules/comment.rules.inc
Implementation of hook_rules_action_info().
node_rules_action_info in rules/modules/node.rules.inc
Implementation of hook_rules_action_info().
path_rules_action_info in rules/modules/path.rules.inc
Implementation of hook_rules_action_info().
php_rules_action_info in rules/modules/php.rules.inc
Implementation of hook_rules_action_info().
rules_forms_rules_action_info in rules_forms/rules_forms.rules.inc
Implementation of hook_rules_action_info().

... See full list

File

rules/rules.api.php, line 114
This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

Code

function hook_rules_action_info() {
  return array(
    'rules_action_mail_to_user' => array(
      'label' => t('Send a mail to a user'),
      'arguments' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('Recipient'),
        ),
      ),
      'module' => 'System',
      'eval input' => array(
        'subject',
        'message',
        'from',
      ),
    ),
  );
}