/**
* Collects the node links in the menu tree.
*
* @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree
* The menu link tree to manipulate.
* @param array $node_links
* Stores references to menu link elements to effectively set access.
*/
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);
} } } /**
* Checks access for one menu link instance.
*
* @param \Drupal\Core\Menu\MenuLinkInterface $instance
* The menu link instance.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/