"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.9/core/modules/forum/src/Breadcrumb/ForumBreadcrumbBuilderBase.php" (18 Nov 2020, 2993 Bytes) of package /linux/www/drupal-8.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ForumBreadcrumbBuilderBase.php" see the Fossies "Dox" file reference documentation.

    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\DependencyInjection\DeprecatedServicePropertyTrait;
    9 use Drupal\Core\Entity\EntityTypeManagerInterface;
   10 use Drupal\Core\Link;
   11 use Drupal\Core\Routing\RouteMatchInterface;
   12 use Drupal\Core\StringTranslation\StringTranslationTrait;
   13 use Drupal\Core\StringTranslation\TranslationInterface;
   14 use Drupal\forum\ForumManagerInterface;
   15 
   16 /**
   17  * Provides a forum breadcrumb base class.
   18  *
   19  * This just holds the dependency-injected config, entity type manager, and
   20  * forum manager objects.
   21  */
   22 abstract class ForumBreadcrumbBuilderBase implements BreadcrumbBuilderInterface {
   23   use StringTranslationTrait;
   24   use DeprecatedServicePropertyTrait;
   25 
   26   /**
   27    * {@inheritdoc}
   28    */
   29   protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
   30 
   31   /**
   32    * Configuration object for this builder.
   33    *
   34    * @var \Drupal\Core\Config\Config
   35    */
   36   protected $config;
   37 
   38   /**
   39    * The entity type manager.
   40    *
   41    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   42    */
   43   protected $entityTypeManager;
   44 
   45   /**
   46    * The forum manager service.
   47    *
   48    * @var \Drupal\forum\ForumManagerInterface
   49    */
   50   protected $forumManager;
   51 
   52   /**
   53    * The taxonomy term storage.
   54    *
   55    * @var \Drupal\taxonomy\TermStorageInterface
   56    */
   57   protected $termStorage;
   58 
   59   /**
   60    * Constructs a forum breadcrumb builder object.
   61    *
   62    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   63    *   The entity type manager.
   64    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   65    *   The configuration factory.
   66    * @param \Drupal\forum\ForumManagerInterface $forum_manager
   67    *   The forum manager service.
   68    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   69    *   The string translation service.
   70    */
   71   public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, ForumManagerInterface $forum_manager, TranslationInterface $string_translation) {
   72     $this->entityTypeManager = $entity_type_manager;
   73     $this->config = $config_factory->get('forum.settings');
   74     $this->forumManager = $forum_manager;
   75     $this->setStringTranslation($string_translation);
   76     $this->termStorage = $entity_type_manager->getStorage('taxonomy_term');
   77   }
   78 
   79   /**
   80    * {@inheritdoc}
   81    */
   82   public function build(RouteMatchInterface $route_match) {
   83     $breadcrumb = new Breadcrumb();
   84     $breadcrumb->addCacheContexts(['route']);
   85 
   86     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
   87 
   88     $vocabulary = $this->entityTypeManager
   89       ->getStorage('taxonomy_vocabulary')
   90       ->load($this->config->get('vocabulary'));
   91     $breadcrumb->addCacheableDependency($vocabulary);
   92     $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
   93 
   94     return $breadcrumb->setLinks($links);
   95   }
   96 
   97 }