public function BreadcrumbManager::build

public BreadcrumbManager::build(RouteMatchInterface $route_match)

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

core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php, line 72

Class

BreadcrumbManager
Provides a breadcrumb manager.

Namespace

Drupal\Core\Breadcrumb

Code

public function build(RouteMatchInterface $route_match) {
  $breadcrumb = new Breadcrumb();
  $context = array('builder' => NULL);
  // Call the build method of registered breadcrumb builders,
  // until one of them returns an array.
  foreach ($this->getSortedBuilders() as $builder) {
    if (!$builder->applies($route_match)) {
      // The builder does not apply, so we continue with the other builders.
      continue;
    }

    $breadcrumb = $builder->build($route_match);

    if ($breadcrumb instanceof Breadcrumb) {
      $context['builder'] = $builder;
      break;
    }
    else {
      throw new \UnexpectedValueException('Invalid breadcrumb returned by ' . get_class($builder) . '::build().');
    }
  }
  // Allow modules to alter the breadcrumb.
  $this->moduleHandler->alter('system_breadcrumb', $breadcrumb, $route_match, $context);

  return $breadcrumb;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Breadcrumb!BreadcrumbManager.php/function/BreadcrumbManager::build/8.1.x