Mercurial > hg > cmmr2012-drupal-site
annotate vendor/chi-teck/drupal-code-generator/templates/d8/service/breadcrumb-builder.twig @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\{{ machine_name }}; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Breadcrumb\Breadcrumb; |
Chris@0 | 6 use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; |
Chris@0 | 7 use Drupal\Core\Link; |
Chris@0 | 8 use Drupal\Core\Routing\RouteMatchInterface; |
Chris@0 | 9 use Drupal\Core\StringTranslation\StringTranslationTrait; |
Chris@0 | 10 use Drupal\node\NodeInterface; |
Chris@0 | 11 |
Chris@0 | 12 /** |
Chris@0 | 13 * Provides a breadcrumb builder for articles. |
Chris@0 | 14 */ |
Chris@0 | 15 class {{ class }} implements BreadcrumbBuilderInterface { |
Chris@0 | 16 |
Chris@0 | 17 use StringTranslationTrait; |
Chris@0 | 18 |
Chris@0 | 19 /** |
Chris@0 | 20 * {@inheritdoc} |
Chris@0 | 21 */ |
Chris@0 | 22 public function applies(RouteMatchInterface $route_match) { |
Chris@0 | 23 $node = $route_match->getParameter('node'); |
Chris@0 | 24 return $node instanceof NodeInterface && $node->getType() == 'article'; |
Chris@0 | 25 } |
Chris@0 | 26 |
Chris@0 | 27 /** |
Chris@0 | 28 * {@inheritdoc} |
Chris@0 | 29 */ |
Chris@0 | 30 public function build(RouteMatchInterface $route_match) { |
Chris@0 | 31 $breadcrumb = new Breadcrumb(); |
Chris@0 | 32 |
Chris@0 | 33 $links[] = Link::createFromRoute($this->t('Home'), '<front>'); |
Chris@0 | 34 |
Chris@0 | 35 // Articles page is a view. |
Chris@0 | 36 $links[] = Link::createFromRoute($this->t('Articles'), 'view.articles.page_1'); |
Chris@0 | 37 |
Chris@0 | 38 $node = $route_match->getParameter('node'); |
Chris@0 | 39 $links[] = Link::createFromRoute($node->label(), '<none>'); |
Chris@0 | 40 |
Chris@0 | 41 $breadcrumb->setLinks($links); |
Chris@0 | 42 |
Chris@0 | 43 return $breadcrumb; |
Chris@0 | 44 } |
Chris@0 | 45 |
Chris@0 | 46 } |