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 * The taxonomy term storage.
48 * @var \Drupal\taxonomy\TermStorageInterface
50 protected $termStorage;
53 * Constructs a forum breadcrumb builder object.
55 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
57 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
58 * The configuration factory.
59 * @param \Drupal\forum\ForumManagerInterface $forum_manager
60 * The forum manager service.
61 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
62 * The string translation service.
64 public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, ForumManagerInterface $forum_manager, TranslationInterface $string_translation) {
65 $this->entityManager = $entity_manager;
66 $this->config = $config_factory->get('forum.settings');
67 $this->forumManager = $forum_manager;
68 $this->setStringTranslation($string_translation);
69 $this->termStorage = $entity_manager->getStorage('taxonomy_term');
75 public function build(RouteMatchInterface $route_match) {
76 $breadcrumb = new Breadcrumb();
77 $breadcrumb->addCacheContexts(['route']);
79 $links[] = Link::createFromRoute($this->t('Home'), '<front>');
81 $vocabulary = $this->entityManager
82 ->getStorage('taxonomy_vocabulary')
83 ->load($this->config->get('vocabulary'));
84 $breadcrumb->addCacheableDependency($vocabulary);
85 $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
87 return $breadcrumb->setLinks($links);