Newer
Older
<?php
/**
* @file
* Contains \Drupal\comment\CommentBreadcrumbBuilder.
*/
namespace Drupal\comment;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderBase;
Angie Byron
committed
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/**
* Class to define the comment breadcrumb builder.
*/
class CommentBreadcrumbBuilder extends BreadcrumbBuilderBase {
/**
* Stores the Entity manager service.
*
Angie Byron
committed
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a CommentBreadcrumbBuilder object.
*
Angie Byron
committed
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
Angie Byron
committed
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
Dries Buytaert
committed
/**
* {@inheritdoc}
*/
public function applies(array $attributes) {
return isset($attributes[RouteObjectInterface::ROUTE_NAME]) && $attributes[RouteObjectInterface::ROUTE_NAME] == 'comment.reply'
&& isset($attributes['entity_type'])
&& isset($attributes['entity_id'])
&& isset($attributes['field_name']);
}
/**
* {@inheritdoc}
*/
public function build(array $attributes) {
Dries Buytaert
committed
$breadcrumb = array();
$breadcrumb[] = $this->l($this->t('Home'), '<front>');
$entity = $this->entityManager
->getStorageController($attributes['entity_type'])
->load($attributes['entity_id']);
Alex Pott
committed
$uri = $entity->urlInfo();
$breadcrumb[] = \Drupal::l($entity->label(), $uri['route_name'], $uri['route_parameters'], $uri['options']);
Dries Buytaert
committed
return $breadcrumb;