You are here

function revisioning_nodeapi in Revisioning 6.4

Same name and namespace in other branches
  1. 6 revisioning.module \revisioning_nodeapi()
  2. 6.3 revisioning.module \revisioning_nodeapi()

Implementation of hook_nodeapi().

This function is called serveral times during the node's life cycle, with different node operations passed in.

Typically when loading a node for viewing, the order is: 'load', 'view', 'alter'

When creating new content: Before displaying the creation form: 'prepare' When saving: 'validate', 'presave', 'insert'

When editing an existing node: Before displaying the edit form: 'load', 'prepare' When saving: 'load', 'validate', 'presave', 'update'

The same $op may be requested multiple times during the same HTTP request, especially 'load'.

File

./revisioning.module, line 353
Allows the creation and modification of pre-published as well as live content while the current revision remains unchanged and publicly visible until the changes have been reviewed by a moderator.

Code

function revisioning_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'load':

      // called at the end of node_load()
      // The revision_moderation flag may be overridden on the node edit form
      // by users with the "administer nodes" permission
      $node->revision_moderation = node_tools_content_is_moderated($node->type);
      $node->is_pending = _revisioning_node_is_pending($node);

      // Could use following, but this seems old style, i.e. when $node is not a &ref

      //$node_extras['revision_moderation'] = $node->revision_moderation;

      //$node_extras['is_pending'] = $node->is_pending;
      break;
    case 'view':

      // called from called from node_view() before $node is fully built
      break;
    case 'alter':

      // called from node_view() after $node is fully built for display
      if (!$teaser && $node->nid == arg(1) && $node->revision_moderation && user_access('view revision status messages')) {
        drupal_set_message(_revisioning_node_info_msg($node));
      }
      break;
    case 'prepare':

      // presenting edit form
      _revisioning_prepare_msg($node);
      break;
    case 'presave':

      // for edits, called from node_save(), prior to _node_save_revision()
      if ($node->revision_moderation) {

        // Tick-box on edit form
        $node->is_pending = _revisioning_node_is_pending($node);
        if ($node->revision && $node->is_pending && variable_get('new_revisions_' . $node->type, NEW_REVISION_WHEN_NOT_PENDING) == NEW_REVISION_WHEN_NOT_PENDING) {
          drupal_set_message(t('Updating existing copy, not creating new revision as this one is still pending.'));

          // Update the $node object just before it is saved to the db
          $node->revision = FALSE;
        }
        if (!$node->status && user_access('publish revisions') && variable_get('revisioning_auto_publish_' . $node->type, FALSE)) {
          drupal_set_message(t('Auto-publishing this revision.'));
          $node->status = TRUE;

          // Make sure current_revision_id is pointing to right revision or
          // subsequent $op='update' will reset it
          $node->current_revision_id = $node->vid;
        }
      }
      break;
    case 'insert':

      // new node, called from node_save(), after _node_save_revision()
      _revisioning_insert_msg($node);
      break;
    case 'update':

      // new node, called from node_save(), after _node_save_revision()
      if ($node->revision_moderation && isset($node->current_revision_id) && $node->current_revision_id != $node->vid) {

        // Resetting vid back to its originial value, thus creating pending revision
        db_query('UPDATE {node} SET vid=%d WHERE nid=%d', $node->current_revision_id, $node->nid);

        //$node->is_pending = TRUE;
      }
      break;
    case 'delete revision':
      module_invoke_all('revisionapi', 'post delete', $node);
      break;
  }
  return;

  // $node_extras;
}