After some hard work, the workflow-ng API is ready. It features
- actions, which may be configurable
- conditions, which may also be configurable
- support for multiple arguments, for actions as well as for conditions
- condition evaluation with logical operations like OR, AND and NOR
- events, for which conditions and actions can be configured. They may be contributed by modules.
- dynamic loading of needed arguments
- ordered conditions and actions - they are evaluated like they are ordered
- form API style configuration and processing of conditions and actions
UpdateThere is now a project for workflow-ng: http://drupal.org/project/workflow_ng To check it out, better use the developer documentation, which is up2date.
Checking it out..So if you are interested in this all, have a look at the API. I'm developing this in my sandbox, but I'm also attaching a module preview to this post. Note, that there is no UI yet, so this is likely only for interest for developers. There is also a README describing all the stuff a bit closer. The module currently comes with some simple testing/demonstrating conditions and actions, located in workflow_ng_tests.inc. Let's take a look at one example, Configuration 4: Notify the node author about changes from other users So this is an example of a module provided configuration of conditions and actions, which may be customized with the (not yet exisiting) UI module by users.
First of we specify the new configuration and that it should be processed on 'node_update', an event defined in workflow_ng_events.inc. This event provides two user arguments, the currently logged in user as wells as the node author. So we configure a condition, that compares these two users and negate it, because we want to fire the action, if the users are not equal. Then we configure the action "workflow_ng_action_mail_node", which mails the content of a node to an user, so it needs to arguments, a node and a user. The '#argument map' property of the action configuration specifies, that we want to mail to the author, and not to the currently logged in user. At last point we add the conditions and the action to the configuration and we are done :)
<?php /* configure actions on node update, that notify the authour about any changes from other users */
$configurations['config4'] = array(
'#type' =?> 'configuration',
'#label' => t('Notify the node author about changes from other users'),
'#event' => 'node_update',
'#module' => 'workflow_ng',
$author_equals_user = workflow_ng_use_condition('workflow_ng_condition_user_comparison', array('#argument map' => array('author' => 'user1', 'user' => 'user2')));
$author_equals_not_user = workflow_ng_configure('NOR', $author_equals_user); //negate
$action_notify = workflow_ng_use_action('workflow_ng_action_mail_node', array('#argument map' => array('author' => 'user')));
$configurations['config4'] = workflow_ng_configure($configurations['config4'], $author_equals_not_user, $action_notify);