function workflow_select_next_state_action in Workflow 6.2
Same name and namespace in other branches
- 5.2 workflow.module \workflow_select_next_state_action()
- 6 workflow_actions/workflow_actions.module \workflow_select_next_state_action()
Implementation of a Drupal action. Move a node to the next state in the workfow.
File
- workflow_actions/
workflow_actions.module, line 77 - Provide actions and triggers for workflows. Why it's own module? Some sites prefer rules, some prefer actions, all prefer a lower code footprint and better performance. Additional creadit to gcassie ( http://drupal.org/user/80260 ) for the…
Code
function workflow_select_next_state_action($node, $context) {
// If this action is being fired because it's attached to a workflow transition
// then the node's new state (now its current state) should be in $node->workflow
// because that is where the value from the workflow form field is stored;
// otherwise the current state is placed in $node->_workflow by our nodeapi load.
if (!isset($node->workflow) && !isset($node->_workflow)) {
watchdog('workflow', 'Unable to get current workflow state of node %nid.', array(
'%nid' => $node->nid,
));
return;
}
$current_state = isset($node->workflow) ? $node->workflow : $node->_workflow;
// Get the node's new state.
$choices = workflow_field_choices($node);
foreach ($choices as $sid => $name) {
if (isset($flag)) {
$new_state = $sid;
$new_state_name = $name;
break;
}
if ($sid == $current_state) {
$flag = TRUE;
}
}
// Fire the transition.
workflow_execute_transition($node, $new_state);
}