You are here

public function MenuTrailByPathActiveTrail::getActiveTrailLink in Menu Trail By Path 8

Fetches the deepest, heaviest menu link which matches the deepest trail path url.

Parameters

string $menu_name: The menu within which to find the active trail link.

Return value

\Drupal\Core\Menu\MenuLinkInterface|NULL The menu link for the given menu, or NULL if there is no matching menu link.

1 call to MenuTrailByPathActiveTrail::getActiveTrailLink()
MenuTrailByPathActiveTrail::doGetActiveTrailIds in src/MenuTrailByPathActiveTrail.php
Helper method for ::getActiveTrailIds().

File

src/MenuTrailByPathActiveTrail.php, line 140

Class

MenuTrailByPathActiveTrail
Overrides the class for the file entity normalizer from HAL.

Namespace

Drupal\menu_trail_by_path

Code

public function getActiveTrailLink($menu_name) {
  $menu_links = $this->menuHelper
    ->getMenuLinks($menu_name);
  $trail_urls = $this->pathHelper
    ->getUrls();
  foreach (array_reverse($trail_urls) as $trail_url) {
    foreach (array_reverse($menu_links) as $menu_link) {

      /* @var $menu_link \Drupal\Core\Menu\MenuLinkInterface */

      /* @var $trail_url \Drupal\Core\Url */
      if ($menu_link
        ->getUrlObject()
        ->toString() == $trail_url
        ->toString()) {
        return $menu_link;
      }
    }
  }
  return NULL;
}