3 namespace Drupal\forum\Breadcrumb;
5 use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
6 use Drupal\Core\Breadcrumb\Breadcrumb;
7 use Drupal\Core\Config\ConfigFactoryInterface;
8 use Drupal\Core\Entity\EntityManagerInterface;
10 use Drupal\Core\Routing\RouteMatchInterface;
11 use Drupal\Core\StringTranslation\StringTranslationTrait;
12 use Drupal\Core\StringTranslation\TranslationInterface;
13 use Drupal\forum\ForumManagerInterface;
16 * Provides a forum breadcrumb base class.
18 * This just holds the dependency-injected config, entity manager, and forum
21 abstract class ForumBreadcrumbBuilderBase implements BreadcrumbBuilderInterface {
22 use StringTranslationTrait;
25 * Configuration object for this builder.
27 * @var \Drupal\Core\Config\Config
34 * @var \Drupal\Core\Entity\EntityManagerInterface
36 protected $entityManager;
39 * The forum manager service.
41 * @var \Drupal\forum\ForumManagerInterface
43 protected $forumManager;
46 * Constructs a forum breadcrumb builder object.
48 * @param \Drupal\Core\Entity\EntityManagerInterface $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.
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);
67 public function build(RouteMatchInterface $route_match) {
68 $breadcrumb = new Breadcrumb();
69 $breadcrumb->addCacheContexts(['route']);
71 $links[] = Link::createFromRoute($this->t('Home'), '<front>');
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');
79 return $breadcrumb->setLinks($links);