Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\taxonomy;
|
||||
|
||||
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
|
||||
use Drupal\Core\Breadcrumb\Breadcrumb;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
|
@ -29,7 +30,7 @@ class TermBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
/**
|
||||
* The taxonomy storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
* @var \Drupal\Taxonomy\TermStorageInterface
|
||||
*/
|
||||
protected $termStorage;
|
||||
|
||||
|
|
@ -56,18 +57,28 @@ class TermBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = new Breadcrumb();
|
||||
$breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
|
||||
$term = $route_match->getParameter('taxonomy_term');
|
||||
// Breadcrumb needs to have terms cacheable metadata as a cacheable
|
||||
// dependency even though it is not shown in the breadcrumb because e.g. its
|
||||
// parent might have changed.
|
||||
$breadcrumb->addCacheableDependency($term);
|
||||
// @todo This overrides any other possible breadcrumb and is a pure
|
||||
// hard-coded presumption. Make this behavior configurable per
|
||||
// vocabulary or term.
|
||||
$breadcrumb = array();
|
||||
while ($parents = $this->termStorage->loadParents($term->id())) {
|
||||
$term = array_shift($parents);
|
||||
$parents = $this->termStorage->loadAllParents($term->id());
|
||||
// Remove current term being accessed.
|
||||
array_shift($parents);
|
||||
foreach (array_reverse($parents) as $term) {
|
||||
$term = $this->entityManager->getTranslationFromContext($term);
|
||||
$breadcrumb[] = Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id()));
|
||||
$breadcrumb->addCacheableDependency($term);
|
||||
$breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id())));
|
||||
}
|
||||
$breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>');
|
||||
$breadcrumb = array_reverse($breadcrumb);
|
||||
|
||||
// This breadcrumb builder is based on a route parameter, and hence it
|
||||
// depends on the 'route' cache context.
|
||||
$breadcrumb->setCacheContexts(['route']);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue