You are here

public function RegistrationBreadcrumbBuilder::build in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Breadcrumb/RegistrationBreadcrumbBuilder.php \Drupal\rng\Breadcrumb\RegistrationBreadcrumbBuilder::build()
  2. 3.x src/Breadcrumb/RegistrationBreadcrumbBuilder.php \Drupal\rng\Breadcrumb\RegistrationBreadcrumbBuilder::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/RegistrationBreadcrumbBuilder.php, line 30

Class

RegistrationBreadcrumbBuilder
Provides a breadcrumb builder for registrations.

Namespace

Drupal\rng\Breadcrumb

Code

public function build(RouteMatchInterface $route_match) {
  $links = [
    Link::createFromRoute($this
      ->t('Home'), '<front>'),
  ];
  $registration = $route_match
    ->getParameter('registration');
  if ($event = $registration
    ->getEvent()) {
    $links[] = new Link($event
      ->label(), $event
      ->urlInfo());
  }
  if ('entity.registration.canonical' != $route_match
    ->getRouteName()) {
    $links[] = new Link($registration
      ->label(), $registration
      ->urlInfo());
  }
  $breadcrumb = new Breadcrumb();
  return $breadcrumb
    ->setLinks($links)
    ->addCacheContexts([
    'route.name',
  ]);
}