function BreadcrumbManager::build

Same name in other branches
  1. 9 core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php \Drupal\Core\Breadcrumb\BreadcrumbManager::build()
  2. 8.9.x core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php \Drupal\Core\Breadcrumb\BreadcrumbManager::build()
  3. 10 core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php \Drupal\Core\Breadcrumb\BreadcrumbManager::build()

Overrides BreadcrumbBuilderInterface::build

File

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

Class

BreadcrumbManager
Provides a breadcrumb manager.

Namespace

Drupal\Core\Breadcrumb

Code

public function build(RouteMatchInterface $route_match) {
    $cacheable_metadata = new CacheableMetadata();
    $breadcrumb = new Breadcrumb();
    $context = [
        '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, $cacheable_metadata)) {
            // 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;
            $breadcrumb->addCacheableDependency($cacheable_metadata);
            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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.