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 Backdrop's convention modulename_description_action), 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 declared as a Backdrop 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 is enough for a basic example. Type is set to system, so users will not be confused about the scope of this action (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, and 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 '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 the t() function for translation.
  • 'callback': Optional. A function name that will execute the action if the name of the action differs from the function name.
  • 'file': Optional. Relative path to a file from the module's directory that contains the callback function. *

See also

hook_action_info()

Related topics

File

modules/examples/action_example/action_example.module, line 105
Action definition example module.

Code

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',
    ),
  );
}