You are here

class ForumListingBreadcrumbBuilder in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/forum/src/Breadcrumb/ForumListingBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
  2. 10 core/modules/forum/src/Breadcrumb/ForumListingBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder

Provides a breadcrumb builder base class for forum listing pages.

Hierarchy

Expanded class hierarchy of ForumListingBreadcrumbBuilder

1 string reference to 'ForumListingBreadcrumbBuilder'
forum.services.yml in core/modules/forum/forum.services.yml
core/modules/forum/forum.services.yml
1 service uses ForumListingBreadcrumbBuilder
forum.breadcrumb.listing in core/modules/forum/forum.services.yml
Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder

File

core/modules/forum/src/Breadcrumb/ForumListingBreadcrumbBuilder.php, line 11

Namespace

Drupal\forum\Breadcrumb
View source
class ForumListingBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    return $route_match
      ->getRouteName() == 'forum.page' && $route_match
      ->getParameter('taxonomy_term');
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = parent::build($route_match);
    $breadcrumb
      ->addCacheContexts([
      'route',
    ]);

    // Add all parent forums to breadcrumbs.

    /** @var \Drupal\taxonomy\TermInterface $term */
    $term = $route_match
      ->getParameter('taxonomy_term');
    $term_id = $term
      ->id();
    $breadcrumb
      ->addCacheableDependency($term);
    $parents = $this->termStorage
      ->loadAllParents($term_id);
    if ($parents) {
      foreach (array_reverse($parents) as $parent) {
        if ($parent
          ->id() != $term_id) {
          $breadcrumb
            ->addCacheableDependency($parent);
          $breadcrumb
            ->addLink(Link::createFromRoute($parent
            ->label(), 'forum.page', [
            'taxonomy_term' => $parent
              ->id(),
          ]));
        }
      }
    }
    return $breadcrumb;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ForumBreadcrumbBuilderBase::$config protected property Configuration object for this builder.
ForumBreadcrumbBuilderBase::$entityTypeManager protected property The entity type manager.
ForumBreadcrumbBuilderBase::$forumManager protected property The forum manager service.
ForumBreadcrumbBuilderBase::$termStorage protected property The taxonomy term storage.
ForumBreadcrumbBuilderBase::__construct public function Constructs a forum breadcrumb builder object.
ForumListingBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
ForumListingBreadcrumbBuilder::build public function Builds the breadcrumb. Overrides ForumBreadcrumbBuilderBase::build
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.