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.
- 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.
examples/ action_example/ action_example.module, line 8
- Action definition example module.
||A simple page to explain to the developer what to do.|
||Action function for action_example_basic_action.|
||Action function for action_example_unblock_user_action.|
||Action function for action_example_node_sticky_action.|
||Form to display the basic action.|