You are here

class RegistrantBreadcrumbBuilder in RNG - Events and Registrations 8.2

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

Provides a breadcrumb builder for registrants.

Hierarchy

Expanded class hierarchy of RegistrantBreadcrumbBuilder

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

File

src/Breadcrumb/RegistrantBreadcrumbBuilder.php, line 15

Namespace

Drupal\rng\Breadcrumb
View source
class RegistrantBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    $registrant = $route_match
      ->getParameter('registrant');
    return $registrant instanceof RegistrantInterface;
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    $links[] = Link::createFromRoute($this
      ->t('Home'), '<front>');

    /** @var \Drupal\rng\Entity\RegistrantInterface $registrant */
    $registrant = $route_match
      ->getParameter('registrant');
    if ($registration = $registrant
      ->getRegistration()) {
      if ($event = $registration
        ->getEvent()) {
        $links[] = new Link($event
          ->label(), $event
          ->toUrl());
      }
      $links[] = new Link($registration
        ->label(), $registration
        ->toUrl());
    }

    // Add registrant to the breadcrumb if the current route is not canonical.
    if ('entity.registrant.canonical' != $route_match
      ->getRouteName()) {
      $links[] = new Link($registrant
        ->label(), $registrant
        ->toUrl());
    }
    $breadcrumb = new Breadcrumb();
    return $breadcrumb
      ->setLinks($links)
      ->addCacheContexts([
      'route.name',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RegistrantBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
RegistrantBreadcrumbBuilder::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.