You are here

function revisioning_node_load in Revisioning 7

Same name and namespace in other branches
  1. 8 revisioning.module \revisioning_node_load()

Implements hook_node_load().

The same load op may occur multiple times during the same HTTP request, so hooray for caching!

hook_node_load is called when viewing a single node node_load() -> node_load_multiple() -> DrupalDefaultEntityController->attachLoad()

hook_node_load is also called on the /content summary page: node_admin_nodes() -> node_load_multiple() -> DrupalDefaultEntityController->attachLoad()

We do nothing in this 2nd case.

File

./revisioning.module, line 392
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_node_load($nodes, $types) {

  // The 'taxonomy/term/%' menu callback taxonomy_term_page() selects nodes
  // based on presence of their nids in the {taxonomy_index} table, which is
  // mainly based on publication status. Revisioning also updates the table for
  // unpublished content so that in Views we can see the terms belonging to
  // published as well as unpublished content. As a result we must re-apply
  // access control when taxonomy feeds are displayed.
  // See also revisioning_update_taxonomy_index().
  //
  $double_check_access = strpos($_GET['q'], 'taxonomy/term') === 0 && variable_get('revisioning_in_views_show_unpublished_content_terms', TRUE);

  // At this point status, comment, promote and sticky have been set on all of
  // the $nodes according to the {node_revision} table (not the {node} table),
  // using {node.vid} as the foreign key into {node_revision}.
  $nodes_to_be_fixed = array();
  foreach ($nodes as $nid => $node) {
    if ($double_check_access && !node_access('view', $node)) {

      // At this point we cannot remove the node object from $nodes,
      // but we can set a flag to be checked in a later hook.
      $node->dont_display = TRUE;
    }
    else {
      revisioning_set_node_revision_info($node);
      if (!empty($node->revision_moderation) && !empty($node->is_current)) {

        // Hack!
        // Because of core issue [#1120272/#542290], if the current revision is
        // loaded, $node fields may in fact be those belonging to LATEST
        // revision.
        // So reload with FIELD_LOAD_REVISION. We can rely on $node->vid, that
        // attribute is set correctly.
        // Make sure to unset the already loaded fields or we end up with 2
        // copies of each field, e.g. 2 bodies, 2 tags, 2 image attachments etc.
        list($nid, $vid, $bundle) = entity_extract_ids('node', $node);
        $instances = _field_invoke_get_instances('node', $bundle, array(
          'deleted' => FALSE,
        ));
        foreach ($instances as $instance) {
          $field_name = $instance['field_name'];
          unset($node->{$field_name});
        }
        $nodes_to_be_fixed[$nid] = $node;
      }
    }
  }
  if (!empty($nodes_to_be_fixed)) {
    field_attach_load_revision('node', $nodes_to_be_fixed);
    foreach ($nodes_to_be_fixed as $nid => $node) {
      $nodes[$nid] = $node;
    }
  }
}