Community Documentation

hook_hook_info

6 core.php hook_hook_info()
7 system.api.php hook_hook_info()
8 system.api.php hook_hook_info()

Expose a list of triggers (events) that users can assign actions to.

Note: Implementing this hook doesn't actually make any action functions run. It just lets the trigger module set up an admin page that will let a site administrator assign actions to hooks. To make this work, module needs to:

  • Detect that the event has happened
  • Figure out which actions have been associated with the event. Currently, the best way to do that is to call _trigger_get_hook_aids(), whose inputs are the name of the hook and the name of the operation, as defined in your hook_hook_info() return value)
  • Call the associated action functions using the actions_do() function.

Return value

A nested array:

  • The outermost array key must be the name of your module.

    • The next key represents the name of the hook that triggers the events, but for custom and contributed modules, it actually must be the name of your module.

      • The next key is the name of the operation within the hook. The array values at this level are arrays; currently, the only recognized key in that array is 'runs when', whose array value gives a translated description of the hook.

See also

hook_action_info(), which allows your module to define actions.

Related topics

▾ 5 functions implement hook_hook_info()

comment_hook_info in modules/comment/comment.module
Implementation of hook_hook_info().
node_hook_info in modules/node/node.module
Implementation of hook_hook_info().
system_hook_info in modules/system/system.module
Implementation of hook_hook_info().
taxonomy_hook_info in modules/taxonomy/taxonomy.module
Implementation of hook_hook_info().
user_hook_info in modules/user/user.module
Implementation of hook_hook_info().

File

developer/hooks/core.php, line 322
These are the hooks that are invoked by the Drupal core.

Code

<?php
function hook_hook_info() {
  return array(
    'comment' => array(
      'comment' => array(
        'insert' => array(
          'runs when' => t('After saving a new comment'),
        ), 
        'update' => array(
          'runs when' => t('After saving an updated comment'),
        ), 
        'delete' => array(
          'runs when' => t('After deleting a comment'),
        ), 
        'view' => array(
          'runs when' => t('When a comment is being viewed by an authenticated user'),
        ),
      ),
    ),
  );
}
?>

Comments

The hook changed name in Drupal 7

In Drupal 7 the hook has been renamed hook_trigger_info().
This hook is still used in Drupal 7, but with a different purpose. See Converting 6.x modules to 7.x for more details.

Howto

Have a look on this howto http://drupal.org/node/375833

Login or register to post comments