class BlogBreadcrumbBuilder in Blog 3.x
Same name and namespace in other branches
- 8.2 src/BlogBreadcrumbBuilder.php \Drupal\blog\BlogBreadcrumbBuilder
Build blog-specific breadcrumb.
Hierarchy
- class \Drupal\blog\BlogBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
Expanded class hierarchy of BlogBreadcrumbBuilder
1 string reference to 'BlogBreadcrumbBuilder'
1 service uses BlogBreadcrumbBuilder
File
- src/
BlogBreadcrumbBuilder.php, line 15
Namespace
Drupal\blogView source
class BlogBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* @var \Drupal\blog\BlogListerInterface
*/
protected $blogLister;
/**
* {@inheritdoc}
*/
public function __construct(BlogListerInterface $blogLister) {
$this->blogLister = $blogLister;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
if ($route_match
->getRouteName() == 'entity.node.canonical') {
/**
* @var \Drupal\node\NodeInterface $node
*/
$node = $route_match
->getParameter('node');
return $node
->bundle() == 'blog_post';
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
/**
* @var \Drupal\node\NodeInterface $node
*/
$node = $route_match
->getParameter('node');
$breadcrumb = new Breadcrumb();
$breadcrumb
->addCacheContexts([
'route',
]);
$links[] = Link::createFromRoute($this
->t('Home'), '<front>');
$links[] = Link::fromTextAndUrl($this
->t('Blogs'), Url::fromUri('internal:/blog'));
$title_text = $this->blogLister
->userBlogTitle($node
->getOwner());
$blog_url = Url::fromUri('internal:/blog/' . $node
->getOwnerId());
$links[] = Link::fromTextAndUrl($title_text, $blog_url);
return $breadcrumb
->setLinks($links);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlogBreadcrumbBuilder:: |
protected | property | ||
BlogBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
BlogBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
BlogBreadcrumbBuilder:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |