You are here

public function TBMegaMenuBuilder::buildPageTrail in The Better Mega Menu 2.x

Same name and namespace in other branches
  1. 8 src/TBMegaMenuBuilder.php \Drupal\tb_megamenu\TBMegaMenuBuilder::buildPageTrail()

Builds the page trail for marking active items.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement[] $menu_items: The menu items to use.

Overrides TBMegaMenuBuilderInterface::buildPageTrail

File

src/TBMegaMenuBuilder.php, line 283

Class

TBMegaMenuBuilder
Defines a TBMegaMenuBuilder.

Namespace

Drupal\tb_megamenu

Code

public function buildPageTrail(array $menu_items) {
  $trail = [];
  foreach ($menu_items as $pluginId => $item) {
    $is_front = $this->pathMatcher
      ->isFrontPage();
    $route_name = $item->link
      ->getPluginDefinition()['route_name'];
    if ($item->inActiveTrail || $route_name == '<front>' && $is_front) {
      $trail[$pluginId] = $item;
    }
    if ($item->subtree) {
      $trail += self::buildPageTrail($item->subtree);
    }
  }
  return $trail;
}