diff --git a/core/modules/menu/lib/Drupal/menu/MenuFormController.php b/core/modules/menu/lib/Drupal/menu/MenuFormController.php index a74899d..fd3f123 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuFormController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuFormController.php @@ -268,13 +268,9 @@ protected function buildOverviewForm(array &$form, array &$form_state) { } $delta = max(count($links), 50); - $tree = $this->menuTree->buildTreeData($links); - $node_links = array(); - $this->menuTree->collectNodeLinks($tree, $node_links); - // We indicate that a menu administrator is running the menu access check. $this->getRequest()->attributes->set('_menu_admin', TRUE); - $this->menuTree->checkAccess($tree, $node_links); + $tree = $this->menuTree->buildTreeData($links); $this->getRequest()->attributes->set('_menu_admin', FALSE); $form = array_merge($form, $this->buildOverviewTreeForm($tree, $delta)); 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 2c3e213..a4d5d7e 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php @@ -492,12 +492,17 @@ protected function doBuildTree($menu_name, array $parameters = array()) { } /** - * {@inheritdoc} + * 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. */ - public function collectNodeLinks(&$tree, &$node_links) { + protected function collectNodeLinks(&$tree, &$node_links) { foreach ($tree as $key => $v) { - if ($tree[$key]['link']['router_path'] == 'node/%') { - $nid = substr($tree[$key]['link']['link_path'], 5); + 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']; $tree[$key]['link']['access'] = FALSE; @@ -510,9 +515,15 @@ public function collectNodeLinks(&$tree, &$node_links) { } /** - * {@inheritdoc} + * 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(). */ - public function checkAccess(&$tree, $node_links = array()) { + protected function checkAccess(&$tree, $node_links = array()) { if ($node_links) { $this->checkNodeLinksAccess($node_links); } @@ -578,9 +589,17 @@ protected function doCheckAccess(&$tree) { * {@inheritdoc} */ public function buildTreeData(array $links, array $parents = array(), $depth = 1) { + $data['tree'] = $this->doBuildTreeData($links, $parents, $depth); + $data['node_links'] = array(); + $this->collectNodeLinks($data['tree'], $data['node_links']); + $this->checkAccess($data['tree'], $data['node_links']); + return $data['tree']; + } + + protected function doBuildTreeData(array $links, array $parents = array(), $depth = 1) { // Reverse the array so we can use the more efficient array_pop() function. $links = array_reverse($links); - return $this->doBuildTreeData($links, $parents, $depth); + return $this->treeDataRecursive($links, $parents, $depth); } /** @@ -604,7 +623,7 @@ public function buildTreeData(array $links, array $parents = array(), $depth = 1 * * @return array */ - protected function doBuildTreeData(&$links, $parents, $depth) { + protected function treeDataRecursive(&$links, $parents, $depth) { $tree = array(); while ($item = array_pop($links)) { // We need to determine if we're on the path to root so we can later build @@ -622,7 +641,7 @@ protected function doBuildTreeData(&$links, $parents, $depth) { // Check whether the next link is the first in a new sub-tree. if ($next && $next['depth'] > $depth) { // Recursively call doBuildTreeData to build the sub-tree. - $tree[$item['mlid']]['below'] = $this->doBuildTreeData($links, $parents, $next['depth']); + $tree[$item['mlid']]['below'] = $this->treeDataRecursive($links, $parents, $next['depth']); // Fetch next link after filling the sub-tree. $next = end($links); } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeInterface.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeInterface.php index 0666c0a..0393e11 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeInterface.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeInterface.php @@ -48,17 +48,6 @@ public function renderTree($tree); public function setPath($menu_name, $path = NULL); /** - * 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(). - */ - public function checkAccess(&$tree, $node_links = array()); - - /** * Gets the path for determining the active trail of the specified menu tree. * * @param string $menu_name @@ -123,16 +112,6 @@ public function buildTreeData(array $links, array $parents = array(), $depth = 1 public function buildPageData($menu_name, $max_depth = NULL, $only_active_trail = FALSE); /** - * 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. - */ - public function collectNodeLinks(&$tree, &$node_links); - - /** * Gets the data structure representing a named menu tree. * * Since this can be the full tree including hidden items, the data returned