class ForumNodeBreadcrumbBuilder in Drupal 10
Same name and namespace in other branches
- 8 core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder
- 9 core/modules/forum/src/Breadcrumb/ForumNodeBreadcrumbBuilder.php \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder
Breadcrumb builder for forum nodes.
Hierarchy
- class \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase implements BreadcrumbBuilderInterface uses StringTranslationTrait
- class \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder
Expanded class hierarchy of ForumNodeBreadcrumbBuilder
1 string reference to 'ForumNodeBreadcrumbBuilder'
- forum.services.yml in core/
modules/ forum/ forum.services.yml - core/modules/forum/forum.services.yml
1 service uses ForumNodeBreadcrumbBuilder
- forum.breadcrumb.node in core/
modules/ forum/ forum.services.yml - Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder
File
- core/
modules/ forum/ src/ Breadcrumb/ ForumNodeBreadcrumbBuilder.php, line 11
Namespace
Drupal\forum\BreadcrumbView source
class ForumNodeBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
return $route_match
->getRouteName() == 'entity.node.canonical' && $route_match
->getParameter('node') && $this->forumManager
->checkNodeType($route_match
->getParameter('node'));
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = parent::build($route_match);
$breadcrumb
->addCacheContexts([
'route',
]);
$parents = $this->termStorage
->loadAllParents($route_match
->getParameter('node')->forum_tid);
if ($parents) {
$parents = array_reverse($parents);
foreach ($parents as $parent) {
$breadcrumb
->addCacheableDependency($parent);
$breadcrumb
->addLink(Link::createFromRoute($parent
->label(), 'forum.page', [
'taxonomy_term' => $parent
->id(),
]));
}
}
return $breadcrumb;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ForumBreadcrumbBuilderBase:: |
protected | property | Configuration object for this builder. | |
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. | |
ForumNodeBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
ForumNodeBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides ForumBreadcrumbBuilderBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 3 |
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. | 1 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |