You are here

public function RegistrantBreadcrumbBuilder::build in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Breadcrumb/RegistrantBreadcrumbBuilder.php \Drupal\rng\Breadcrumb\RegistrantBreadcrumbBuilder::build()
  2. 8 src/Breadcrumb/RegistrantBreadcrumbBuilder.php \Drupal\rng\Breadcrumb\RegistrantBreadcrumbBuilder::build()

Builds the breadcrumb.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

\Drupal\Core\Breadcrumb\Breadcrumb A breadcrumb.

Overrides BreadcrumbBuilderInterface::build

File

src/Breadcrumb/RegistrantBreadcrumbBuilder.php, line 30

Class

RegistrantBreadcrumbBuilder
Provides a breadcrumb builder for registrants.

Namespace

Drupal\rng\Breadcrumb

Code

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',
  ]);
}