| 1 system.api.php | hook_action_info() |
Declares information about actions.
Any module can define actions, and then call actions_execute() to make those actions happen in response to events.
An action consists of two parts:
- an action definition (returned by this hook)
- a function which performs the action (which by convention is named MODULE_description-of-function_action)
@since 1.32.3 Added "access callback" and "access arguments".
Return value
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'.
- '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.
- 'access callback': A function name that will return TRUE if the user account executing the action has permission to run the action, and FALSE if not. If set to TRUE, access to this action is always allowed. Defaults to TRUE. In Backdrop 2.x, the default will be changed to 'user_access'.
- 'access arguments': Optional. An array of arguments to pass to the access callback function. Usually this is an array with a permission name within it, which is passed to user_access().
- 'file': Optional. Relative path to a file from the module's directory that contains the callback function.
See also
action_get_info()
Related topics
File
- core/
modules/ system/ system.api.php, line 3636 - Hooks provided by Backdrop core and the System module.
Code
function hook_action_info() {
return array(
'comment_unpublish_action' => array(
'type' => 'comment',
'label' => t('Unpublish comment'),
'callback' => 'comment_unpublish_action',
'access callback' => 'user_access',
'access arguments' => array('administer comments'),
),
);
}