You are here

function workflow_select_next_state_action in Workflow 5.2

Same name and namespace in other branches
  1. 6.2 workflow_actions/workflow_actions.module \workflow_select_next_state_action()
  2. 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.module, line 678

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', t('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);
}