function ForumNodeBreadcrumbBuilder::build

Same name in other branches
  1. 9 core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder::build()
  2. 8.9.x core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder::build()
  3. 11.x core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder::build()

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.