PracticalWeb Ltd

Websites that work for you.

Triggers in Drupal

To make a Drupal module that provides triggers you need to

  1. Use module_invoke_all at the point your code triggers an event. This basically defines a hook that your module provides - it has to be called after the name of your module because of a bug
  2. Define your modules implementation of this hook to run any actions registered for it. ‘mymodule’, ‘op’ => $op, ‘arg2’ => $arg2, (arg3 etc) ); actions_do(array_keys($aids), $arg1, $context); } ?> You can wrap up as many arguments as you like in the context array, $op can be used to define related actions like the way the user module has op for insert, delete, update etc. $arg1 is passed by reference as the $object parameter to actions.
  3. Tell Drupal about your triggers by implementing hook_hook_info This adds the triggers on the triggers admin page array( ‘mymodule’ => array( ‘some_op’ => array( ‘runs when’ => t(‘Text to explain when the trigger runs’), ), ‘some_other_op’ => array( ‘runs when’ => t(‘more user text’), ), ), ), ); } ?>
  4. Now you can use the admin interface to run actions when your triggers fire.

See Writing triggers (Drupal 6.x) for more details - I wrote this up as I found it helpful to approach the issue in reverse order to that page.