You are here

class RuleComponentBreadcrumbBuilder in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Breadcrumb/RuleComponentBreadcrumbBuilder.php \Drupal\rng\Breadcrumb\RuleComponentBreadcrumbBuilder
  2. 3.x src/Breadcrumb/RuleComponentBreadcrumbBuilder.php \Drupal\rng\Breadcrumb\RuleComponentBreadcrumbBuilder

Provides a breadcrumb builder for RNG rule components.

Hierarchy

Expanded class hierarchy of RuleComponentBreadcrumbBuilder

1 string reference to 'RuleComponentBreadcrumbBuilder'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses RuleComponentBreadcrumbBuilder
rng.breadcrumb.rule_component in ./rng.services.yml
Drupal\rng\Breadcrumb\RuleComponentBreadcrumbBuilder

File

src/Breadcrumb/RuleComponentBreadcrumbBuilder.php, line 15

Namespace

Drupal\rng\Breadcrumb
View source
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 = array(
      Link::createFromRoute($this
        ->t('Home'), '<front>'),
    );

    /** @var \Drupal\rng\RuleComponentInterface $component */
    $component = $route_match
      ->getParameter('rng_rule_component');
    if ($rule = $component
      ->getRule()) {
      if ($event = $rule
        ->getEvent()) {
        $links[] = new Link($event
          ->label(), $event
          ->urlInfo());
      }
    }
    $breadcrumb = new Breadcrumb();
    return $breadcrumb
      ->setLinks($links)
      ->addCacheContexts([
      'route.name',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RuleComponentBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
RuleComponentBreadcrumbBuilder::build public function Builds the breadcrumb. Overrides BreadcrumbBuilderInterface::build
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.