hook_hook_info

Definition

hook_hook_info()
contributions/docs/developer/hooks/core.php, line 300

Description

Expose a list of triggers (events) that your module is allowing users to assign actions to.

This hook is used by the Triggers API to present information about triggers (or events) that your module allows users to assign actions to.

See also hook_action_info().

For example, the node_hook_info implementation has 'node' as the outermost key, as that's the module it's in. Next it has 'nodeapi' as the next key, as hook_nodeapi() is what applies to changes in nodes. Finally the keys after that are the various operations for hook_nodeapi() that the node module is exposing as triggers.

Return value

  • A nested array. The outermost key defines the module that the triggers are from. The menu system will use the key to look at the .info file of the module and make a local task (a tab) in the trigger UI.
    • The next key defines the hook being described.
      • Inside of that array are a list of arrays keyed by hook operation.
        • Each of those arrays have a key of 'runs when' and a value which is an English description of the hook.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

function hook_hook_info() {
  return array(
    'node' => array(
      'nodeapi' => array(
        'presave' => array(
          'runs when' => t('When either saving a new post or updating an existing post'),
        ),
        'insert' => array(
          'runs when' => t('After saving a new post'),
        ),
        'update' => array(
          'runs when' => t('After saving an updated post'),
        ),
        'delete' => array(
          'runs when' => t('After deleting a post')
        ),
        'view' => array(
          'runs when' => t('When content is viewed by an authenticated user')
        ),
      ),
    ),
  );
}