RuleComponentBreadcrumbBuilder.php in RNG - Events and Registrations 3.x
Same filename and directory in other branches
Namespace
Drupal\rng\BreadcrumbFile
src/Breadcrumb/RuleComponentBreadcrumbBuilder.phpView source
<?php
namespace Drupal\rng\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\rng\Entity\RuleComponentInterface;
use Drupal\Core\Link;
use Drupal\Core\Breadcrumb\Breadcrumb;
/**
* Provides a breadcrumb builder for RNG rule components.
*/
class RuleComponentBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
$component = $route_match
->getParameter('rng_rule_component');
return $component instanceof RuleComponentInterface;
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$links = [
Link::createFromRoute($this
->t('Home'), '<front>'),
];
/** @var \Drupal\rng\Entity\RuleComponentInterface $component */
$component = $route_match
->getParameter('rng_rule_component');
if ($rule = $component
->getRule()) {
if ($event = $rule
->getEvent()) {
$links[] = new Link($event
->label(), $event
->toUrl());
}
}
$breadcrumb = new Breadcrumb();
return $breadcrumb
->setLinks($links)
->addCacheContexts([
'route.name',
]);
}
}
Classes
Name | Description |
---|---|
RuleComponentBreadcrumbBuilder | Provides a breadcrumb builder for RNG rule components. |