You are here

public function PrettyPathBreadcrumb::build in Facets Pretty Paths 8

Builds the breadcrumb.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

\Drupal\Core\Breadcrumb\Breadcrumb A breadcrumb.

Overrides BreadcrumbBuilderInterface::build

File

src/PrettyPathBreadcrumb.php, line 32

Class

PrettyPathBreadcrumb
Pretty Paths breadcrumb builder.

Namespace

Drupal\facets_pretty_paths

Code

public function build(RouteMatchInterface $route_match) {
  $breadcrumb = new Breadcrumb();
  $breadcrumb
    ->addCacheContexts([
    'route',
  ]);
  $route_object = $route_match
    ->getRouteObject();
  $route_without_facets_query = explode('/{facets_query}', $route_object
    ->getPath())[0];
  $request = \Drupal::request();
  $title = \Drupal::service('title_resolver')
    ->getTitle($request, $route_object);
  $url = Url::fromUserInput($route_without_facets_query);
  $links[] = Link::createFromRoute($this
    ->t('Home'), '<front>');
  $links[] = Link::fromTextAndUrl($title, $url);
  return $breadcrumb
    ->setLinks($links);
}