diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php index 7ea3eda..bc62399 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php @@ -409,10 +409,10 @@ public function renderTree($tree) { */ public function buildTree($menu_name, array $parameters = array()) { // Build the menu tree. - $data = $this->doBuildTree($menu_name, $parameters); + $tree = $this->doBuildTree($menu_name, $parameters); // Check access for the current user to each item in the tree. - $this->checkAccess($data['tree'], $data['node_links']); - return $data['tree']; + $this->checkAccess($tree); + return $tree; } /** @@ -479,98 +479,30 @@ protected function doBuildTree($menu_name, array $parameters = array()) { $links = $this->menuLinkStorage->loadMultiple($result); } $active_trail = (isset($parameters['active_trail']) ? $parameters['active_trail'] : array()); - $data['tree'] = $this->buildTreeData($links, $active_trail, $min_depth); - $data['node_links'] = array(); - $this->collectNodeLinks($data['tree'], $data['node_links']); + $tree = $this->doBuildTreeData($links, $active_trail, $min_depth); // Cache the data, if it is not already in the cache. - $this->cache->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name)); - $this->menuTree[$tree_cid] = $data; + $this->cache->set($tree_cid, $tree, Cache::PERMANENT, array('menu' => $menu_name)); + $this->menuTree[$tree_cid] = $tree; } return $this->menuTree[$tree_cid]; } /** - * Collects node links from a given menu tree recursively. - * - * @param array $tree - * The menu tree you wish to collect node links from. - * @param array $node_links - * An array in which to store the collected node links. - */ - protected function collectNodeLinks(&$tree, &$node_links) { - foreach ($tree as $key => $v) { - if ($tree[$key]['link']['route_name'] == 'node.view') { - $nid = $tree[$key]['link']['route_parameters']['node']; - if (is_numeric($nid)) { - $node_links[$nid][$tree[$key]['link']['mlid']] = &$tree[$key]['link']; - } - } - if ($tree[$key]['below']) { - $this->collectNodeLinks($tree[$key]['below'], $node_links); - } - } - } - - /** - * Checks access and performs dynamic operations for each link in the tree. - * - * @param array $tree - * The menu tree you wish to operate on. - * @param array $node_links - * A collection of node link references generated from $tree by - * menu_tree_collect_node_links(). - */ - protected function checkAccess(&$tree, $node_links = array()) { - if ($node_links) { - $this->checkNodeLinksAccess($node_links); - } - $this->doCheckAccess($tree); - } - - /** - * Checks access on node links using the node_access query tag. - * - * @param array $node_links - * An array of node links keyed by NID. - * - * @return mixed - * The node links. - */ - protected function checkNodeLinksAccess(array $node_links) { - $nids = array_keys($node_links); - $select = $this->database->select('node_field_data', 'n'); - $select->addField('n', 'nid'); - // @todo This should be actually filtering on the desired node status field - // language and just fall back to the default language. - $select->condition('n.status', 1); - - $select->condition('n.nid', $nids, 'IN'); - $select->addTag('node_access'); - $nids = $select->execute()->fetchCol(); - foreach ($nids as $nid) { - foreach ($node_links[$nid] as $mlid => $link) { - $node_links[$nid][$mlid]['access'] = TRUE; - } - } - return $node_links; - } - - /** * Sorts the menu tree and recursively checks access for each item. * * @param array $tree * The menu tree you wish to operate on. */ - protected function doCheckAccess(&$tree) { + protected function checkAccess(&$tree) { $new_tree = array(); foreach ($tree as $key => $v) { $item = &$tree[$key]['link']; $this->menuLinkTranslate($item); if ($item['access'] || ($item['in_active_trail'] && strpos($item['href'], '%') !== FALSE)) { if ($tree[$key]['below']) { - $this->doCheckAccess($tree[$key]['below']); + $this->checkAccess($tree[$key]['below']); } // The weights are made a uniform 5 digits by adding 50000 as an offset. // After _menu_link_translate(), $item['title'] has the localized link @@ -589,9 +521,7 @@ protected function doCheckAccess(&$tree) { */ public function buildTreeData(array $links, array $parents = array(), $depth = 1) { $tree = $this->doBuildTreeData($links, $parents, $depth); - $node_links = array(); - $this->collectNodeLinks($tree, $node_links); - $this->checkAccess($tree, $node_links); + $this->checkAccess($tree); return $tree; }