1 action_example.module action_example_action_info()

Implements hook_action_info().

We call hook_action_info when we are defining the actions we provide. Actions are the actions fired by the associated triggers. In this example, we are registering our three new actions, providing the unique name (using the modulename_description_action convention), an easy-to-understand description of what the action does, the 'object' expected by this action (default options from core are node, user, comment and system, however other trigger modules may declare new object types), which are the triggers allowed to use these action, and if some customization is available. Please, note that the function name is not required to end in "_action" to be an action.

These are the actions being provided in hook_action_info().

  • action_example_basic_action: This action is a dummy function which can be used by any trigger. The label describes that the action will do nothing, but it is enough for a basic example. Type is set to system, so users won't be confused about the action scope (expecting a node, user, or any other object).
  • action_example_unblock_user_action: Unblocks a user.
  • action_example_node_unpublish_action: In this example action, the action will unpublish only nodes created by the logged-in user.

We return an associative array of action descriptions. The keys of the array are the names of the action functions; each corresponding value is an associative array with the following key-value pairs:

  • 'type': The type of object this action acts upon. Core actions have types like 'node', 'user', 'comment', and 'system', but additional types can be used, as long as the trigger and action agree on them.
  • 'label': The human-readable name of the action, which should be passed through t().
  • 'callback': (Optional) A function name that will execute the action if the name of the action differs from the function name.
  • 'file': (Optional) The relative path from the module's directory for a file that contains the callback function.

See also


Related topics


modules/examples/action_example/action_example.module, line 97
Hook implementations for the Action Example module.


function action_example_action_info() {
  return array(
    'action_example_basic_action' => array(
      'label' => t('Action Example: A basic example action that does nothing'),
      'type' => 'system',
    'action_example_unblock_user_action' => array(
      'label' => t('Action Example: Unblock a user'),
      'type' => 'user',
    'action_example_node_unpublish_action' => array(
      'type' => 'node',
      'label' => t('Action Example: Unpublish node if created by logged-in user'),
      'callback' => 'action_example_node_unpublish_callback',