You are here

function _revisioning_operation_appropriate in Revisioning 7

Same name and namespace in other branches
  1. 8 revisioning.module \_revisioning_operation_appropriate()
  2. 6.4 revisioning.module \_revisioning_operation_appropriate()
  3. 6.3 revisioning.module \_revisioning_operation_appropriate()

Test whether the supplied revision operation is appropriate for the node.

This is irrespective of user permissions, e.g. even for an administrator it doesn't make sense to publish a node that is already published or to "revert" to the current revision.

Parameters

string $revision_op: For instance 'publish revisions', 'delete revisions'

object $node: The node object

Return value

bool TRUE if the operation is appropriate for this node at this point

1 call to _revisioning_operation_appropriate()
_revisioning_access_node_revision in ./revisioning.module
Determine whether the supplied revision operation is permitted on the node.

File

./revisioning.module, line 873
Allows content to be updated and reviewed before submitting it for publication, while the current live revision remains unchanged and publicly visible until the changes have been reviewed and found fit for publication by a moderator.

Code

function _revisioning_operation_appropriate($revision_op, $node) {
  switch ($revision_op) {
    case 'compare to current':

    // Can't compare against itself.
    case 'delete revisions':

      // If the revision is the current one, suppress the delete operation
      // @TODO ...unless it's the only revision, in which case delete the
      // entire node; however this requires a different URL.
      return !$node->is_current;
    case 'delete archived revisions':
      break;
    case 'view revision list':

      // For i.e. node revisions summary.
      if (empty($node->revision_moderation) && isset($node->num_revisions) && $node->num_revisions == 1) {

        // Suppress Revisions tab when when there's only 1 revision. This is
        // consistent with core.
        // However, when content is moderated (i.e. "New revision in draft,
        // pending moderation" is ticked) we want to be able to get to the
        // 'Unpublish current' link on this page and the 'Publish' tab on
        // the next.
        return FALSE;
      }
      break;
    case 'edit revisions':
      if (empty($node->revision_moderation)) {
        return FALSE;
      }
      break;
    case 'publish revisions':

      // If the node isn't meant to be moderated,
      // or the revision is not either pending or current but not published,
      // then disallow publication.
      if (empty($node->revision_moderation) || !($node->is_pending || $node->is_current && !$node->status)) {
        return FALSE;
      }
      break;
    case 'unpublish current revision':

      // If the node isn't meant to be moderated or it is unpublished already
      // or we're not looking at the current revision, then unpublish is not an
      // option.
      if (empty($node->revision_moderation) || !$node->status || !$node->is_current) {
        return FALSE;
      }
      break;
    case 'revert revisions':

      // If this revision is pending or current, suppress the reversion.
      if ($node->is_pending || $node->is_current) {
        return FALSE;
      }
      break;
  }
  return TRUE;
}