Preserve return value of an action and act before transition
miiimooo - April 10, 2008 - 11:34
| Project: | Workflow |
| Version: | 5.x-2.x-dev |
| Component: | -workflow_workflow_ng |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
The workflow module allows implementation of a pre transition trigger.
This is already almost handled in workflow-ng.
The only problem is that workflow-ng doesn't care about return values or pass them on to worklfow.
e.g. I have a custom PHP action that simply returns FALSE. This is triggered whenever the workflow status is about to change (pre transition). I would expect this to block or veto the worklflow status change. But the return value from the PHP action doesn't get returned to workflow.

#1
This patch allows vetoing workflow state changes.
It's done quick and dirty. Can someone check whether it's okay and doesn't break anything else.
It basically adds a pseudo argument ('result') that stores the return value(s) of any actions and returns them at the end to the caller.
The patch consists of two parts. One is a patch to the workflow_ng module of workflow. The second one to the workflow_ng.module.
To give an example of how to test how this works try this:
* In worflow_ng create a rule configuration
Invoked on event: Workflow is about to be updated* Select the action "Execute custom PHP code" and put this code in there:
<?phpdrupal_set_message("dummy vetoing state change");
return FALSE;
?>
Now, when you go into the workflow of a node and try to change it will print the message but even better it won't change the state!
#2
I've now also added a patch to workflow #256652: Token for the future workflow state for use during validate phase. This adds a token for state:workflow-future-state-name.
BTW no one has commented so far on these patches though I thought they were really useful. Is this a completely wrong approach?
#3
Workflow-ng doesn't support return values. However you can modify passed with actions and return new arguments with an action.
The workflow-ng integration of workflow ships with workflow, show I move this to workflow.
#4
Thanks for your reply. Just trying to clarify what you said above and I am not quite sure how I can return false to the to the pre transition invocation without using a return value? Because that's the only way to "block" a state change. Or is there an argument that the action would need to set/modify?
#5
Sorry to keep on asking about this but.. if I understand it right the way to do this would be to move the part that does the pre transition check (validate stage) into the condition and then have an action that approximately says "block workflow state change". Is that would mean? If it is just one more question: is there already an action for this or would I have to write one?