You are here

public function ContextMenuActiveTrail::getActiveLink in Context 8.4

Same name and namespace in other branches
  1. 8 src/ContextMenuActiveTrail.php \Drupal\context\ContextMenuActiveTrail::getActiveLink()

Fetches a menu link which matches the route name, parameters and menu name.

Parameters

string|null $menu_name: (optional) The menu within which to find the active link. If omitted, all menus will be searched.

Return value

\Drupal\Core\Menu\MenuLinkInterface|null The menu link for the given route name, parameters and menu, or NULL if there is no matching menu link or the current user cannot access the current page (i.e. we have a 403 response).

Overrides MenuActiveTrail::getActiveLink

File

src/ContextMenuActiveTrail.php, line 34

Class

ContextMenuActiveTrail
Extend the MenuActiveTrail class.

Namespace

Drupal\context

Code

public function getActiveLink($menu_name = NULL) {
  $found = parent::getActiveLink($menu_name);

  // Get active reaction of Menu type.
  foreach ($this->contextManager
    ->getActiveReactions('menu') as $reaction) {
    $menu_items = $reaction
      ->execute();
    foreach ($menu_items as $menu_link_content) {
      $menu = strtok($menu_link_content, ':');
      if ($menu == $menu_name) {
        $plugin_id = substr($menu_link_content, strlen($menu) + 1);
        return $this->menuLinkManager
          ->createInstance($plugin_id);
      }
    }
  }
  return $found;
}