This example demonstrates how to create actions.

Actions are a feature that allows some programming without using PHP. Using the appropriate action in a specific event, a site administrator can add new functionality.

Examples are:

  • Displaying a message after a user has logged in
  • Displaying a message after a node has been deleted
  • Unblocking a user if selected in a Views list

In Backdrop core, actions are mainly run by adding them to bulk operations executed on Views lists, although modules may also trigger actions by calling actions_execute().

Actions are very often grouped by functionality: user, node, taxonomy. When actions are grouped, it is because they expect the same arguments.

Not all actions can be used in all triggers because they require different contexts, but some actions are generic enough to not require special objects in their contexts; they can be used on every available trigger.

What are good candidates to be triggers? Any function can be a trigger, as long as it has the code to call the action, but to make Backdrop more extensible, you will find hooks very good candidates. A trigger should build the arguments, ask for enqueued actions and run them. You may define a function being a trigger, and run it through a button in the front page, or you may prepare a trigger for a hook, and everytime that hook is fired, your trigger will be.

What are good candidates to be actions? Any function is a possible action; the only problem is finding a trigger able to run it.

This module shows how to create actions. We are providing three actions:

  • A generic action that can be used in any trigger, which is the most basic example of an action
  • A user action
  • A node action

For this module, the generic action will be triggered by executing a submission handler in a form. The Node and User actions will be triggered from a Views bulk operations form.

Parent topics


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


Namesort descending Location Description
action_example_action_info modules/examples/action_example/action_example.module Implements hook_action_info().
action_example_basic_action modules/examples/action_example/action_example.module Action function for action_example_basic_action.
action_example_basic_action_form modules/examples/action_example/action_example.module Form to display the basic action.
action_example_basic_action_form_submit modules/examples/action_example/action_example.module
action_example_config_info modules/examples/action_example/action_example.module Implements hook_config_info().
action_example_menu modules/examples/action_example/action_example.module Implements hook_menu().
action_example_node_unpublish_callback modules/examples/action_example/action_example.module Action function for action_example_node_sticky_action.
action_example_unblock_user_action modules/examples/action_example/action_example.module Action function for action_example_unblock_user_action.
_action_example_page modules/examples/action_example/action_example.module A simple page to explain to the developer what to do.


Namesort descending Location Description
ActionExampleTestCase modules/examples/action_example/tests/action_example.test Default test case for the action_example module.