Created
December 5, 2013 14:44
-
-
Save damiankloip/7806182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains \Drupal\comment\CommentBreadcrumbBuilder. | |
*/ | |
namespace Drupal\comment; | |
use Drupal\Core\Breadcrumb\BreadcrumbBuilderBase; | |
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. | |
* | |
* @var \Drupal\Core\Entity\EntityManagerInterface | |
*/ | |
protected $entityManager; | |
/** | |
* Constructs a CommentBreadcrumbBuilder object. | |
* | |
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | |
* The entity manager. | |
*/ | |
public function __construct(EntityManagerInterface $entity_manager) { | |
$this->entityManager = $entity_manager; | |
} | |
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) { | |
$breadcrumb[] = $this->l($this->t('Home'), '<front>'); | |
$entity = $this->entityManager | |
->getStorageController($attributes['entity_type']) | |
->load($attributes['entity_id']); | |
$uri = $entity->uri(); | |
$breadcrumb[] = l($entity->label(), $uri['path'], $uri['options']); | |
return $breadcrumb; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment