Creating actions in Backdrop

Actions are Backdrop features allowing some Backdrop programming without using PHP. Using the appropriate action in a specific event, a site administrator can add new functionality.

Examples are:

  • Display a message after a user has logged in.
  • Display a message after a node has been deleted.
  • Unblock 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: examples are '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 that they do not require special objects in their contexts, and so 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 (from Backdrop and contributed modules) 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 describes how to create actions for Backdrop. In this example 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 submit function in a simple form. The Node and User actions will be triggered from a Views bulk operations form.

See also

hook_action_info()

Parent topics

File

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

Functions

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.

Classes

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