You are here

public static function WeMegaMenuBuilder::buildPageTrail in Drupal Mega Menu 8

Same name and namespace in other branches
  1. 8.x src/WeMegaMenuBuilder.php \Drupal\we_megamenu\WeMegaMenuBuilder::buildPageTrail()

Get trail array.

Return value

array Public static function buildPageTrail array.

2 calls to WeMegaMenuBuilder::buildPageTrail()
template_preprocess_we_megamenu_backend in ./we_megamenu.module
template_preprocess_we_megamenu_frontend in ./we_megamenu.module
Prepare variables for we_megamenu_frontend.

File

src/WeMegaMenuBuilder.php, line 711

Class

WeMegaMenuBuilder

Namespace

Drupal\we_megamenu

Code

public static function buildPageTrail($menu_items) {
  $trail = [];
  foreach ($menu_items as $key_item => $item) {
    $plugin_id = $item['plugin_id'];
    $check_is_front_page = Drupal::service('path.matcher')
      ->isFrontPage();
    $route_name = $item['route_name'];
    if ($route_name == '<front>' && $check_is_front_page) {
      $trail[$plugin_id] = $item;
    }
    elseif (isset($item['in_active_trail']) && $item['in_active_trail'] == 1) {
      $trail[$plugin_id] = $item;
    }
    if (isset($item['subtree']) && count($item['subtree'])) {
      $trail += self::buildPageTrail($item['subtree']);
    }
  }
  return $trail;
}