Version 1.1 (checked in on 2010/12/13 at 17:44:36 by rfay)
Action definition example module.
Triggers and actions are a matched pair of Drupal features allowing some Drupal programming without using PHP. Using the appropriate action in a specific event, a site administrator can add new functionality. Examples are:
A trigger is a special function which can enqueue actions. The trigger module provides the interface allowing us to associate certain actions with certain triggers.
Actions are the functions designed to be run by triggers.
A trigger should build the appropriate context for the action to be fired. Actions are very often grouped by functionality: examples are 'user', 'node', 'taxonomy'. When actions are grouped it is because they expect the same arguments. This way, you can enqueue as many actions understanding the 'user' object as you want.
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. This 'group' type is used by actions to be available for this trigger.
What are good candidates to be triggers? Any function can be a trigger, as long as it has the code to call the enqueued actions, but to make Drupal more extensible, you will find hooks (from Drupal 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 Drupal. In this example we are providing three actions:
See:
@todo this is a drupal 6 link Writing Actions
@todo this is a drupal 6 link Triggers and Actions in Drupal 7
hook_action_info() In addition, the Trigger Example provides detailed information on how to create a trigger.
| Name | Description |
|---|---|
| action_example_action_info | Implements hook_action_info(). |
| action_example_basic_action | Basic example action. |
| action_example_menu | Implements hook_menu(). |
| action_example_node_sticky_action | Promote and set sticky flag action. This is the special action that has been customized using the configuration form. |
| action_example_node_sticky_action_form | Generates settings form for action_example_node_sticky_action(). |
| action_example_node_sticky_action_submit | Submit handler for action_example_node_sticky_action. |
| action_example_node_sticky_action_validate | Validate settings form for action_example_node_sticky_action(). Verify that user exists before continuing. |
| action_example_unblock_user_action | Unblock an user. This action can be fired from different trigger types: |
| _action_example_page | A simple page to explain to the developer what to do. |