You are here

protected function MenuBlock::findLinkInTree in Menu Block 8

Gets the menu link item from the menu tree.

Parameters

array $menu_tree: Associative array containing the menu link tree data.

string $link_id: Menu link id to find.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement|null The link element from the given menu tree or NULL if it can't be found.

1 call to MenuBlock::findLinkInTree()
MenuBlock::getLinkTitleFromLink in src/Plugin/Block/MenuBlock.php
Gets the title of a given menu item ID.

File

src/Plugin/Block/MenuBlock.php, line 542

Class

MenuBlock
Provides an extended Menu block.

Namespace

Drupal\menu_block\Plugin\Block

Code

protected function findLinkInTree(array $menu_tree, $link_id) {
  if (isset($menu_tree[$link_id])) {
    return $menu_tree[$link_id];
  }

  /** @var \Drupal\Core\Menu\MenuLinkTreeElement $link */
  foreach ($menu_tree as $link) {
    $link = $this
      ->findLinkInTree($link->subtree, $link_id);
    if ($link) {
      return $link;
    }
  }
}