function hook_hook_info

7 system.api.php hook_hook_info()
6 core.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()

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

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().
3 invocations of hook_hook_info()
trigger_assign in modules/trigger/trigger.admin.inc
Build the form that allows users to assign actions to hooks.
trigger_forms in modules/trigger/trigger.module
Implementation of hook_forms(). We reuse code by using the same assignment form definition for each node-op combination.
trigger_menu in modules/trigger/trigger.module
Implementation of hook_menu().

File

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

Code

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

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.

This is true, but it can be a real gotcha. A trigger is something different from a hook, and this function was (strangely) used in D6 to declare triggers, not hooks.

Basically, a hook is an event which is handled in code - they are never presented to the user or administrator. A trigger is an event which a site administrator can assign actions to using the administrative interface.

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