Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / forum / src / Breadcrumb / ForumBreadcrumbBuilderBase.php
1 <?php
2
3 namespace Drupal\forum\Breadcrumb;
4
5 use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
6 use Drupal\Core\Breadcrumb\Breadcrumb;
7 use Drupal\Core\Config\ConfigFactoryInterface;
8 use Drupal\Core\Entity\EntityManagerInterface;
9 use Drupal\Core\Link;
10 use Drupal\Core\Routing\RouteMatchInterface;
11 use Drupal\Core\StringTranslation\StringTranslationTrait;
12 use Drupal\Core\StringTranslation\TranslationInterface;
13 use Drupal\forum\ForumManagerInterface;
14
15 /**
16  * Provides a forum breadcrumb base class.
17  *
18  * This just holds the dependency-injected config, entity manager, and forum
19  * manager objects.
20  */
21 abstract class ForumBreadcrumbBuilderBase implements BreadcrumbBuilderInterface {
22   use StringTranslationTrait;
23
24   /**
25    * Configuration object for this builder.
26    *
27    * @var \Drupal\Core\Config\Config
28    */
29   protected $config;
30
31   /**
32    * The entity manager.
33    *
34    * @var \Drupal\Core\Entity\EntityManagerInterface
35    */
36   protected $entityManager;
37
38   /**
39    * The forum manager service.
40    *
41    * @var \Drupal\forum\ForumManagerInterface
42    */
43   protected $forumManager;
44
45   /**
46    * Constructs a forum breadcrumb builder object.
47    *
48    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
49    *   The entity manager.
50    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
51    *   The configuration factory.
52    * @param \Drupal\forum\ForumManagerInterface $forum_manager
53    *   The forum manager service.
54    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
55    *   The string translation service.
56    */
57   public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, ForumManagerInterface $forum_manager, TranslationInterface $string_translation) {
58     $this->entityManager = $entity_manager;
59     $this->config = $config_factory->get('forum.settings');
60     $this->forumManager = $forum_manager;
61     $this->setStringTranslation($string_translation);
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function build(RouteMatchInterface $route_match) {
68     $breadcrumb = new Breadcrumb();
69     $breadcrumb->addCacheContexts(['route']);
70
71     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
72
73     $vocabulary = $this->entityManager
74       ->getStorage('taxonomy_vocabulary')
75       ->load($this->config->get('vocabulary'));
76     $breadcrumb->addCacheableDependency($vocabulary);
77     $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
78
79     return $breadcrumb->setLinks($links);
80   }
81
82 }