You are here

function action_workflow_execute_transition in Workflow 5

Implementation of a Drupal action. Changes the workflow state of a node to the next state of the workflow.

File

./workflow.module, line 491

Code

function action_workflow_execute_transition($op, $edit = array(), &$node) {
  switch ($op) {
    case 'do':

      // if this action is being fired because it's attached to a workflow transition
      // then the node's new state (now it's current state) should be in $node->workflow;
      // 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

      //$new_state = $edit['target_state']; // change to specific state not yet implemented
      $new_state = '';
      if ($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
      watchdog('action', t('Changing workflow state of node id %id to %state', array(
        '%id' => intval($node->nid),
        '%state' => check_plain($new_state_name),
      )));
      workflow_execute_transition($node, $new_state);
      watchdog('action', t('Changed workflow state of node id %id to %state', array(
        '%id' => intval($node->nid),
        '%state' => check_plain($new_state_name),
      )));
      break;
    case 'metadata':
      return array(
        'description' => t('Change workflow state of a node to next state'),
        'type' => t('Workflow'),
        'batchable' => TRUE,
        'configurable' => FALSE,
      );

    // return an HTML config form for the action
    case 'form':
      return '';

    // validate the HTML form
    case 'validate':
      return TRUE;

    // process the HTML form to store configuration
    case 'submit':
      return '';
  }
}