You are here

protected function Tracker::getMenuLinkLevel in Menu Entity Index 8

Gets menu level of a menu link.

Recursive method.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $menu_link: The menu link plugin to get the level for.

int $level: Used internally to track level during recursive calls.

Return value

int Menu level of the menu link.

1 call to Tracker::getMenuLinkLevel()
Tracker::addEntityTargets in src/Tracker.php
Inserts a database entry for each target entity of the given host entity.

File

src/Tracker.php, line 620

Class

Tracker
Tracks menu links and their referenced entities.

Namespace

Drupal\menu_entity_index

Code

protected function getMenuLinkLevel(MenuLinkInterface $menu_link, $level = 0) {
  $parent_id = $menu_link
    ->getParent();
  if (!empty($parent_id) && $this->menuLinkManager
    ->hasDefinition($parent_id)) {
    $parent_link = $this->menuLinkManager
      ->createInstance($parent_id);
    if ($parent_link) {
      return $this
        ->getMenuLinkLevel($parent_link, $level + 1);
    }
    return $level;
  }
  else {
    return $level;
  }
}