You are here

function state_flow_node_presave in State Machine 7.2

Same name and namespace in other branches
  1. 6 modules/state_flow/state_flow.module \state_flow_node_presave()
  2. 7 modules/state_flow/state_flow.module \state_flow_node_presave()

Implements hook_node_presave().

File

modules/state_flow/state_flow.module, line 154
An implementation of node revision workflow for Drupal based on the State Machine system.

Code

function state_flow_node_presave($node) {

  // If the node is not new and is not marked to be ignored by
  // state_flow_promote_node_revision(), then check its current state.
  if (!empty($node->nid) && empty($node->stateflow_ignore_state)) {
    $state_flow = state_flow_load_state_machine($node);

    //Check to see if we should go through workflow for new nodes
    if (!state_flow_skip_workflow($node)) {
      if (!$state_flow
        ->ignore()) {
        $state = $state_flow
          ->get_current_state();
        if ($state == 'published') {

          // If the node being updated is in the published state, then ensure that
          // changes are saved to a new revision.
          $node->revision = TRUE;
        }
        else {
          if ($state != 'draft') {

            // If the node being updated is not in the draft state, then mark this
            // node to be reverted to draft state.
            $node->state_flow_revert_draft = TRUE;
          }
        }
      }
    }
    else {
      if ($node->status) {
        $state_flow
          ->fire_event($state_flow
          ->skip_to_publish(), 1, 'Workflow skipped.');
      }
    }
  }
}