You are here

public function MenuLinkTitle::getTitle in Breadcrumb Manager 8

Get title.

Parameters

string $path: The path.

\Symfony\Component\HttpFoundation\Request $request: The Request.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The Route match.

Return value

string The resolved title.

Overrides BreadcrumbTitleResolverInterface::getTitle

File

src/Plugin/BreadcrumbTitleResolver/MenuLinkTitle.php, line 58

Class

MenuLinkTitle
Class MenuLinkTitle.

Namespace

Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolver

Code

public function getTitle($path, Request $request, RouteMatchInterface $route_match) {
  $route_name = $route_match
    ->getRouteName();
  $route_parameters = $route_match
    ->getRawParameters()
    ->all();
  $menu_links = $this->menuLinkManager
    ->loadLinksByRoute($route_name, $route_parameters);
  if (empty($menu_links)) {
    return FALSE;
  }
  $titles = [];
  foreach ($menu_links as $menu_link) {
    $menu = $menu_link
      ->getMenuName();
    $titles[$menu] = $menu_link
      ->getTitle();
  }
  return isset($titles['main']) ? $titles['main'] : reset($titles);
}