class CommentBreadcrumbBuilder in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/CommentBreadcrumbBuilder.php \Drupal\comment\CommentBreadcrumbBuilder
Class to define the comment breadcrumb builder.
Hierarchy
- class \Drupal\comment\CommentBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
Expanded class hierarchy of CommentBreadcrumbBuilder
1 string reference to 'CommentBreadcrumbBuilder'
- comment.services.yml in core/
modules/ comment/ comment.services.yml - core/modules/comment/comment.services.yml
1 service uses CommentBreadcrumbBuilder
- comment.breadcrumb in core/
modules/ comment/ comment.services.yml - Drupal\comment\CommentBreadcrumbBuilder
File
- core/
modules/ comment/ src/ CommentBreadcrumbBuilder.php, line 20 - Contains \Drupal\comment\CommentBreadcrumbBuilder.
Namespace
Drupal\commentView source
class CommentBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* The comment storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $storage;
/**
* Constructs the CommentBreadcrumbBuilder.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->storage = $entity_manager
->getStorage('comment');
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
return $route_match
->getRouteName() == 'comment.reply' && $route_match
->getParameter('entity');
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$breadcrumb
->addCacheContexts([
'route',
]);
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Home'), '<front>'));
$entity = $route_match
->getParameter('entity');
$breadcrumb
->addLink(new Link($entity
->label(), $entity
->urlInfo()));
$breadcrumb
->addCacheableDependency($entity);
if (($pid = $route_match
->getParameter('pid')) && ($comment = $this->storage
->load($pid))) {
/** @var \Drupal\comment\CommentInterface $comment */
$breadcrumb
->addCacheableDependency($comment);
// Display link to parent comment.
// @todo Clean-up permalink in https://www.drupal.org/node/2198041
$breadcrumb
->addLink(new Link($comment
->getSubject(), $comment
->urlInfo()));
}
return $breadcrumb;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommentBreadcrumbBuilder:: |
protected | property | The comment storage. | |
CommentBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
CommentBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
CommentBreadcrumbBuilder:: |
public | function | Constructs the CommentBreadcrumbBuilder. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
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. |