You are here

function state_flow_prevent_live_revision in State Machine 7

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

Checks whether the version of the node being saved is in the published state, and if not, re-saves the latest published revision.

To prevent field content of a draft node revision from being used as the published version, we need to re-save the current published version after any draft revision is saved.

In Drupal 7, the old approach of "munging the node vid" is not compatible with fields. See: http://drupal.org/node/1184318

1 call to state_flow_prevent_live_revision()
state_flow_node_update in modules/state_flow/state_flow.module
Implements hook_node_update().

File

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

Code

function state_flow_prevent_live_revision($node) {

  // If this node is marked to be ignored by state_flow_promote_node_revision(),
  // then skip handling it.
  if (!empty($node->state_flow_ignore_state)) {
    return;
  }

  // If the revision being saved is not the current published version, then
  // ensure that the published version is re-saved to make it the most recent.
  $published_revision = state_flow_live_revision($node->nid);
  if (!empty($published_revision[0]->vid) && $published_revision[0]->vid != $node->vid) {
    state_flow_promote_node_revision($published_revision[0], $node->nid, $published_revision[0]->vid);

    // When a draft is saved and does not become the current revision, then
    // redirect the user to the revision saved. This hijacks the redirection by
    // drupal_goto().
    $_GET['destination'] = 'node/' . $node->nid . '/revisions/' . $node->vid . '/view';
  }
}