You are here

protected function DefaultMenuLinkTreeManipulators::collectNodeLinks in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::collectNodeLinks()
  2. 9 core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::collectNodeLinks()

Collects the node links in the menu tree.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu link tree to manipulate.

array $node_links: Stores references to menu link elements to effectively set access.

File

core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php, line 174

Class

DefaultMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\Core\Menu

Code

protected function collectNodeLinks(array &$tree, array &$node_links) {
  foreach ($tree as $key => &$element) {
    if ($element->link
      ->getRouteName() == 'entity.node.canonical') {
      $nid = $element->link
        ->getRouteParameters()['node'];
      $node_links[$nid][$key] = $element;

      // Deny access by default. checkNodeAccess() will re-add it.
      $element->access = AccessResult::neutral();
    }
    if ($element->hasChildren) {
      $this
        ->collectNodeLinks($element->subtree, $node_links);
    }
  }
}