Modules may add further events, on which actions and conditions may be configured by either the UI or modules.

To do so, you need to implement hook_rules_event_info().
Let's have a look at a virtual example. Consider the buddylist module supports rules. It could introduce a new event: "User1 adds user2 to their buddylist".

<?php
/**
 * Implementation of hook_rules_event_info().
 * @ingroup rules
 */
function yourmodule_rules_event_info() {
  return array(
    'buddylist_add' => array(
      'label' => t('UserA adds userB to their buddylist'),
      'module' => 'Buddylist',
      'arguments' => array(
        'userA' => array('type' => 'user', 'label' => t('UserA, which adds userB.')),
        'userB' => array('type' => 'user', 'label' => t('UserB, which is added to UserA\'s list.')),
      ),
    ),
  );
}
?>

So 'buddylist_add' is the machine readable event name, which should be unique. So best prefix it with your module name.

Then, the module could invoke the event, when it occurs, by calling:

<?php
  rules_invoke_event('buddylist_add', $userA, $userB); 
?>

That's it. Have a look at the event info reference for more details on the available properties.

Note that all event related code except the invocation can live in the .rules.inc file as described here. So best the invocation is added directly to the .module file and wrapped into a module_exists('rules') check.

Comments

Chris Gillis’s picture

Worth noting: This has changed in Drupal 7. Refer to API.

varshith’s picture

In Drupal 7, 'arguments' is changed to 'variables'