You are here

public function ForumNodeBreadcrumbBuilder::build in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder::build()

Builds the breadcrumb.

Parameters

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

Return value

\Drupal\Core\Breadcrumb\Breadcrumb A breadcrumb.

Overrides ForumBreadcrumbBuilderBase::build

File

core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php, line 25

Class

ForumNodeBreadcrumbBuilder
Breadcrumb builder for forum nodes.

Namespace

Drupal\forum\Breadcrumb

Code

public function build(RouteMatchInterface $route_match) {
  $breadcrumb = parent::build($route_match);
  $breadcrumb
    ->addCacheContexts([
    'route',
  ]);
  $parents = $this->termStorage
    ->loadAllParents($route_match
    ->getParameter('node')->forum_tid);
  if ($parents) {
    $parents = array_reverse($parents);
    foreach ($parents as $parent) {
      $breadcrumb
        ->addCacheableDependency($parent);
      $breadcrumb
        ->addLink(Link::createFromRoute($parent
        ->label(), 'forum.page', [
        'taxonomy_term' => $parent
          ->id(),
      ]));
    }
  }
  return $breadcrumb;
}