You are here

function menu_tree_check_access in Drupal 7

Same name and namespace in other branches
  1. 6 includes/menu.inc \menu_tree_check_access()

Checks access and performs dynamic operations for each link in the tree.

Parameters

$tree: The menu tree you wish to operate on.

$node_links: A collection of node link references generated from $tree by menu_tree_collect_node_links().

Related topics

3 calls to menu_tree_check_access()
book_menu_subtree_data in modules/book/book.module
Gets the data representing a subtree of the book hierarchy.
menu_build_tree in includes/menu.inc
Builds a menu tree, translates links, and checks access.
menu_overview_form in modules/menu/menu.admin.inc
Form for editing an entire menu tree at once.

File

includes/menu.inc, line 1498
API for the Drupal menu system.

Code

function menu_tree_check_access(&$tree, $node_links = array()) {
  if ($node_links && (user_access('access content') || user_access('bypass node access'))) {
    $nids = array_keys($node_links);
    $select = db_select('node', 'n');
    $select
      ->addField('n', 'nid');

    // When a menu administrator who we know has permission to see unpublished
    // nodes is administering the menu, included the unpublished nodes in the
    // tree, with a special flag so that the Menu module can label them.
    // Otherwise, exclude these nodes from the tree.
    if (!empty($GLOBALS['menu_admin']) && user_access('bypass node access')) {
      $select
        ->addField('n', 'status');
    }
    else {
      $select
        ->condition('n.status', 1);
    }
    $select
      ->condition('n.nid', $nids, 'IN');
    $select
      ->addTag('node_access');
    $node_objects = $select
      ->execute()
      ->fetchAll();
    foreach ($node_objects as $node_object) {
      foreach ($node_links[$node_object->nid] as $mlid => $link) {
        $node_links[$node_object->nid][$mlid]['access'] = TRUE;
        if (isset($node_object->status)) {
          $node_links[$node_object->nid][$mlid]['node_unpublished'] = !$node_object->status;
        }
      }
    }
  }
  _menu_tree_check_access($tree);
}