Jump to:
| Project: | Workflow |
| Version: | 6.x-1.4 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Issue Summary
In my current usage of the workflow, I need to let a *specific user* execute a transition, based on a user reference field in the node instead of a user role. I also ran into other scenarios that are more indirect. I thus came up with a generic mechanism to allow modules to specific dynamic transitions, given a state, a user account, and a node. This patch is attached.
The way it works is by calling 2 new hooks at the relevant places. hook_workflow_transitions_alter alters the current allowable transitions to include new ones or stop existing ones. hook_workflow_transitions_info lists the modules that will intercept the transitions to display them on the admin transition grid.
A typical usage of these hooks would be thus:
<?php
// Define the sids we care about.
define('WF_STATE_1', 1);
define('WF_STATE_2', 2);
define('WF_STATE_3', 3);
function mymodule_workflow_transitions_info() {
return array(
WF_STATE_3 => array(
WF_STATE_2 => t('Let the admin go back to state 2'),
WF_STATE_1 => t('Let the referenced user go back to state 1'),
),
);
}
function mymodule_workflow_transitions_alter(&$transitions, $sid, $account, $node) {
if ($sid == WF_STATE_3) {
if ($account->uid == 1) {
$transitions[WF_STATE_2] = workflow_get_state_name(WF_STATE_2);
}
if ($node->field_user[0]['uid'] == $account->uid) {
$transitions[WF_STATE_1] = workflow_get_state_name(WF_STATE_1);
}
}
}
?>Thanks for your consideration. I'll be glad to enhance and polish this patch if needed.
| Attachment | Size |
|---|---|
| workflow-dynamic-transitions.patch | 4.53 KB |
Comments
#1
Subscribing.
#2
@maijs: why exportables?
#3
Sorry, nevermind.
#4
Mixing transitions info in db and code doesn't look right to me. Isn't this more like a guard condition on the transition, which should only been executed if the condition pass ?
#5
@k4ml: no, this is not intended as a guard condition. On the contrary, it is meant to open up new transitions, based on conditions that the core workflow module cannot verify since it restricts itself to roles-based transitions.
This patch opens up the possibility for 3rd party modules to create their own data-driven transitions based on other criteria. For example, one such module would alter the workflow state transition grid to show CCK user reference fields for each state. Only users referenced in the selected field would be able to make the transition. This information would be stored in a separate database table, and the new module would open up this transition through the hooks introduced in the current patch.
#6
Subscribing.
#7
Subscribing
#8
Fixing title.
#9
Interesting idea, can you roll me a patch against Drupal 7?
#10
I'm afraid I'm not working with D7 at the moment.