class SocialCommentBreadcrumbBuilder in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.2 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.3 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.4 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.5 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.6 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.7 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 8.8 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 10.3.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 10.0.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 10.1.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
- 10.2.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder
Class to define the comment breadcrumb builder.
Hierarchy
- class \Drupal\social_comment\SocialCommentBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
Expanded class hierarchy of SocialCommentBreadcrumbBuilder
1 string reference to 'SocialCommentBreadcrumbBuilder'
- social_comment.services.yml in modules/
social_features/ social_comment/ social_comment.services.yml - modules/social_features/social_comment/social_comment.services.yml
1 service uses SocialCommentBreadcrumbBuilder
- social_comment.breadcrumb in modules/
social_features/ social_comment/ social_comment.services.yml - Drupal\social_comment\SocialCommentBreadcrumbBuilder
File
- modules/
social_features/ social_comment/ src/ SocialCommentBreadcrumbBuilder.php, line 16
Namespace
Drupal\social_commentView source
class SocialCommentBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* The comment storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $storage;
/**
* Constructs the SocialCommentBreadcrumbBuilder.
*
* @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) {
$comments_routes = [
'comment.reply',
'entity.comment.edit_form',
'entity.comment.delete_form',
];
return in_array($route_match
->getRouteName(), $comments_routes);
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$breadcrumb
->addCacheContexts([
'route',
]);
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Home'), '<front>'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Home'), '<front>'));
switch ($route_match
->getRouteName()) {
case 'comment.reply':
$page_title = $this
->t('Reply to Comment');
$pid = $route_match
->getParameter('pid');
$comment = $this->storage
->load($pid);
break;
case 'entity.comment.edit_form':
$page_title = $this
->t('Edit Comment');
$comment = $route_match
->getParameter('comment');
break;
case 'entity.comment.delete_form':
$page_title = $this
->t('Delete Comment');
$comment = $route_match
->getParameter('comment');
break;
default:
$page_title = $this
->t('Comment');
}
// Add Entity path to Breadcrumb for Reply.
if ($route_match
->getParameter('entity')) {
$entity = $route_match
->getParameter('entity');
$breadcrumb
->addLink(new Link($entity
->label(), $entity
->urlInfo()));
$breadcrumb
->addCacheableDependency($entity);
}
// Add Caching.
if ($comment) {
$breadcrumb
->addCacheableDependency($comment);
}
// Display link to current page.
$breadcrumb
->addLink(new Link($page_title, Url::fromRoute('<current>')));
return $breadcrumb;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialCommentBreadcrumbBuilder:: |
protected | property | The comment storage. | |
SocialCommentBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
SocialCommentBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
SocialCommentBreadcrumbBuilder:: |
public | function | Constructs the SocialCommentBreadcrumbBuilder. | |
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. |