You are here

function _workbench_moderation_revision_access in Workbench Moderation 7.3

Same name and namespace in other branches
  1. 7 workbench_moderation.module \_workbench_moderation_revision_access()

Wrapper for the 'revert' and 'delete' operations of _node_revision_access().

Drupal core's "current revision" of a node is the version in {node}; for Workbench Moderation, latest revision in {node_revision} is the current revision. For nodes with a published revision, Workbench Moderation keeps that revision in {node}, whether or not it is the current revision.

1 call to _workbench_moderation_revision_access()
workbench_moderation_node_history_view in ./workbench_moderation.node.inc
Display a node's moderation history.
1 string reference to '_workbench_moderation_revision_access'
workbench_moderation_menu_alter in ./workbench_moderation.module
Implements hook_menu_alter().

File

./workbench_moderation.module, line 498
Content moderation for Workbench.

Code

function _workbench_moderation_revision_access($node, $op) {

  // Normal behavior for unmoderated nodes.
  if (!workbench_moderation_node_moderated($node)) {
    return _node_revision_access($node, $op);
  }

  // Prevent reverting to (ie, update) the current revision.
  if ($node->workbench_moderation['current']->vid == $node->workbench_moderation['my_revision']->vid) {
    if ($op == 'update') {
      return FALSE;
    }
  }

  // Prevent deleting the current revision, if there is no separate published
  // revision. This also prevents deleting the current revision if it is the
  // only revision, and its unpublished.
  if ($node->workbench_moderation['current']->vid == $node->workbench_moderation['my_revision']->vid) {
    if ($op == 'delete' && !isset($node->workbench_moderation['published'])) {

      // In theory, deleting the one and only revision of a node could be
      // allowed but we'd need to add special logic that actually deletes
      // the node, not just the revision.
      return FALSE;
    }
  }

  // Prevent deleting a published revision.
  if (isset($node->workbench_moderation['published']) && $node->workbench_moderation['published']->vid == $node->workbench_moderation['my_revision']->vid) {
    if ($op == 'delete') {

      // In theory, deleting a published revision could be allowed but we'd
      // need to solve the problem of determining what to do if you delete the
      // published revision, e.g., what database tables and fields would need
      // to be cascaded for such a change.
      return FALSE;
    }
  }

  // Check access.
  return _node_revision_access($node, $op);
}