You are here

public function BlogBreadcrumbBuilder::build in Blog 8.2

Same name and namespace in other branches
  1. 3.x src/BlogBreadcrumbBuilder.php \Drupal\blog\BlogBreadcrumbBuilder::build()

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/BlogBreadcrumbBuilder.php, line 48

Class

BlogBreadcrumbBuilder
Build blog-specific breadcrumb.

Namespace

Drupal\blog

Code

public function build(RouteMatchInterface $route_match) {

  /**
  * @var \Drupal\node\NodeInterface $node
  */
  $node = $route_match
    ->getParameter('node');
  $breadcrumb = new Breadcrumb();
  $breadcrumb
    ->addCacheContexts([
    'route',
  ]);
  $links[] = Link::createFromRoute($this
    ->t('Home'), '<front>');
  $links[] = Link::fromTextAndUrl($this
    ->t('Blogs'), Url::fromUri('internal:/blog'));
  $title_text = $this->blogLister
    ->userBlogTitle($node
    ->getOwner());
  $blog_url = Url::fromUri('internal:/blog/' . $node
    ->getOwnerId());
  $links[] = Link::fromTextAndUrl($title_text, $blog_url);
  return $breadcrumb
    ->setLinks($links);
}