Mercurial > hg > cmmr2012-drupal-site
view vendor/chi-teck/drupal-code-generator/templates/d8/service/breadcrumb-builder.twig @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
line wrap: on
line source
<?php namespace Drupal\{{ machine_name }}; use Drupal\Core\Breadcrumb\Breadcrumb; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\node\NodeInterface; /** * Provides a breadcrumb builder for articles. */ class {{ class }} implements BreadcrumbBuilderInterface { use StringTranslationTrait; /** * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { $node = $route_match->getParameter('node'); return $node instanceof NodeInterface && $node->getType() == 'article'; } /** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $links[] = Link::createFromRoute($this->t('Home'), '<front>'); // Articles page is a view. $links[] = Link::createFromRoute($this->t('Articles'), 'view.articles.page_1'); $node = $route_match->getParameter('node'); $links[] = Link::createFromRoute($node->label(), '<none>'); $breadcrumb->setLinks($links); return $breadcrumb; } }