Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / forum / src / Breadcrumb / ForumNodeBreadcrumbBuilder.php
1 <?php
2
3 namespace Drupal\forum\Breadcrumb;
4
5 use Drupal\Core\Link;
6 use Drupal\Core\Routing\RouteMatchInterface;
7
8 /**
9  * Breadcrumb builder for forum nodes.
10  */
11 class ForumNodeBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function applies(RouteMatchInterface $route_match) {
17     return $route_match->getRouteName() == 'entity.node.canonical'
18       && $route_match->getParameter('node')
19       && $this->forumManager->checkNodeType($route_match->getParameter('node'));
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function build(RouteMatchInterface $route_match) {
26     $breadcrumb = parent::build($route_match);
27     $breadcrumb->addCacheContexts(['route']);
28
29     $parents = $this->forumManager->getParents($route_match->getParameter('node')->forum_tid);
30     if ($parents) {
31       $parents = array_reverse($parents);
32       foreach ($parents as $parent) {
33         $breadcrumb->addCacheableDependency($parent);
34         $breadcrumb->addLink(Link::createFromRoute($parent->label(), 'forum.page',
35           [
36             'taxonomy_term' => $parent->id(),
37           ]
38         ));
39       }
40     }
41
42     return $breadcrumb;
43   }
44
45 }