function workflow_vbo_next_state_action in Workflow 7
Same name and namespace in other branches
- 7.2 workflow_vbo/actions/next.action.inc \workflow_vbo_next_state_action()
Implements a Drupal action. Move a node to the next state in the workflow.
File
- workflow_vbo/
workflow_vbo.module, line 32 - Provide workflow actions for VBO. Split out from workflow_actions.
Code
function workflow_vbo_next_state_action($node, array $context) {
global $user;
// 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->nid)) {
watchdog('workflow_vbo', 'Unable to get current node id state of node - node is not yet saved.');
return;
}
if (!isset($node->workflow)) {
watchdog('workflow_vbo', 'Unable to get current workflow state of node %nid.', array(
'%nid' => $node->nid,
));
return;
}
$entity_type = 'node';
$entity = $node;
$current_sid = $node->workflow;
$current_state = WorkflowState::load($current_sid);
// Get the node's new state.
$new_sid = $current_sid;
$options = $current_state
->getOptions($entity_type, $entity);
foreach ($options as $sid => $name) {
if (isset($flag)) {
$new_sid = $sid;
$new_state_name = $name;
break;
}
if ($sid == $current_sid) {
$flag = TRUE;
}
}
// Fire the transition.
$transition = new WorkflowTransition($entity_type, $entity, $field_name = '', $current_sid, $new_sid, $user->uid, REQUEST_TIME, $comment = '');
$new_sid = $transition
->execute($force = FALSE);
}