class ForumListingBreadcrumbBuilder in Drupal 8
Same name and namespace in other branches
- 9 core/modules/forum/src/Breadcrumb/ForumListingBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
- 10 core/modules/forum/src/Breadcrumb/ForumListingBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
Provides a breadcrumb builder base class for forum listing pages.
Hierarchy
- class \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase implements BreadcrumbBuilderInterface uses DeprecatedServicePropertyTrait, StringTranslationTrait
- class \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
Expanded class hierarchy of ForumListingBreadcrumbBuilder
1 file declares its use of ForumListingBreadcrumbBuilder
- ForumListingBreadcrumbBuilderTest.php in core/
modules/ forum/ tests/ src/ Unit/ Breadcrumb/ ForumListingBreadcrumbBuilderTest.php
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\BreadcrumbView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
ForumBreadcrumbBuilderBase:: |
protected | property | Configuration object for this builder. | |
ForumBreadcrumbBuilderBase:: |
protected | property | ||
ForumBreadcrumbBuilderBase:: |
protected | property | The entity type manager. | |
ForumBreadcrumbBuilderBase:: |
protected | property | The forum manager service. | |
ForumBreadcrumbBuilderBase:: |
protected | property | The taxonomy term storage. | |
ForumBreadcrumbBuilderBase:: |
public | function | Constructs a forum breadcrumb builder object. | |
ForumListingBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
ForumListingBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides ForumBreadcrumbBuilderBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |