You are here

function hook_rules_event_info in Rules 6

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

Define rules events.

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

Return value

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

Possible attributes for each sub-array are:

  • 'label' The label of the event. Start capitalized. Required.
  • 'module' The providing module's user readable name. Used for grouping the events in the interface. Should start with a capital letter. Required.
  • 'arguments' An array describing the arguments provided by the event with the argument's name as key. Optional. Each argument has to be described by a sub-array with possible attributes as described afterwards.
  • 'help' A help text for rules associated with this event. Optional.

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. See http://drupal.org/node/298633 for a list of known types. Required.
  • 'handler' A handler to load the actual argument value. This is useful for lazy loading variables. The handler gets all available variables passed in the order as defined. Optional. Also see http://drupal.org/node/298554.
  • 'saved' If the variable is saved afterwards, set this to TRUE. So rules knows about it and won't save the variable a second time. Optional (defaults to FALSE).

The module has to invoke the event when it occurs using rules_invoke_event(). This function call has to happen outside of MODULENAME.rules.inc, usually it's invoked directly from the providing module but wrapped by a module_exists('rules') check.

@see rules_invoke_event().

Related topics

6 functions implement hook_rules_event_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_event_info in rules/modules/comment.rules.inc
Implementation of hook_rules_event_info()
node_rules_event_info in rules/modules/node.rules.inc
Implementation of hook_rules_event_info()
rules_forms_rules_event_info in rules_forms/rules_forms.rules.inc
Implementation of hook_rules_event_info().
system_rules_event_info in rules/modules/system.rules.inc
Implementation of hook_rules_event_info().
taxonomy_rules_event_info in rules/modules/taxonomy.rules.inc
Implementation of hook_rules_event_info().

... See full list

File

rules/rules.api.php, line 349
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_event_info() {
  return array(
    'user_insert' => array(
      'label' => t('User account has been created'),
      'module' => 'User',
      'arguments' => rules_events_hook_user_arguments(t('registered user')),
    ),
    'user_update' => array(
      'label' => t('User account details have been updated'),
      'module' => 'User',
      'arguments' => rules_events_hook_user_arguments(t('updated user')) + array(
        'account_unchanged' => array(
          'type' => 'user',
          'label' => t('unchanged user'),
        ),
      ),
    ),
    'user_view' => array(
      'label' => t('User page has been viewed'),
      'module' => 'User',
      'arguments' => rules_events_hook_user_arguments(t('viewed user')),
      'help' => t("Note that if drupal's page cache is enabled, this event won't be generated for pages served from cache."),
    ),
    'user_delete' => array(
      'label' => t('User has been deleted'),
      'module' => 'User',
      'arguments' => rules_events_hook_user_arguments(t('deleted user')),
    ),
    'user_login' => array(
      'label' => t('User has logged in'),
      'module' => 'User',
      'arguments' => array(
        'account' => array(
          'type' => 'user',
          'label' => t('logged in user'),
        ),
      ),
    ),
    'user_logout' => array(
      'label' => t('User has logged out'),
      'module' => 'User',
      'arguments' => array(
        'account' => array(
          'type' => 'user',
          'label' => t('logged out user'),
        ),
      ),
    ),
  );
}