Workflow-ng API ready...

Submitted by fago on Wed, 05/30/2007 - 22:35
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
So workflow-ng works event based. (And no, I'm not talking of calendars ;) E.g. workflow-ng defines some basic events for drupal core, like 'node update, 'node insert', 'user update' and so on. So this are the events you can react on by defining conditions and actions for them. What makes workflow-ng powerful is, is it's flexible handling of arguments. Each of these events has to define a list of available arguments. Then any conditions and actions, that can work with these arguments, can be configured for this event. So an action can be used in any situation, where the suitable arguments are available. There is no need for the action, to be coded aware of every event.. :) As modules may define further events, this enables module authors, to easily allow site administrators to customize the behavior by just defining some further events.

Update

There 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.
<?php /* configure actions on node update, that notify the authour about any changes from other users */
 
$configurations['config4'] = array(
   
'#type' =?>
'configuration',
    '#label' =&gt; t('Notify the node author about changes from other users'),
    '#event' =&gt; 'node_update',
    '#module' =&gt; 'workflow_ng',
  );
  $author_equals_user = workflow_ng_use_condition('workflow_ng_condition_user_comparison', array('#argument map' =&gt; array('author' =&gt; 'user1', 'user' =&gt; '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' =&gt; array('author' =&gt; 'user')));
  $configurations['config4'] = workflow_ng_configure($configurations['config4'], $author_equals_not_user, $action_notify);
?&gt;
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 :)

TODO

This all is already working fine, but there is still a lot of work todo: * Try achieving compatibility with drupal 6 actions * Write a lot of conditions, actions, events.. for drupal core and states. * Write flexible, token module enabled conditions and actions. * Write docs, docs and more docs. * Write a simple UI, that allows the configuration of conditions and actions. * Write a states CCK field with configurable state changes and state changes permissions.

tonyhrx (not verified)

Mon, 06/04/2007 - 18:29

Am I being thick as I cant make head nor tail of the Node Profile demo on the site. Cant really get past page 1 to be honest.

amitaibu@drupal.org (not verified)

Tue, 07/03/2007 - 16:12

One action I'll be looking for: Copy a (CCK) field from one content type to another, while submitting a form. This can be used for example in a cart - When the users orders an item, automatically the Price field is copied from the Product into an Order Item content type. Cheers, Amitai