You are here

public function LazyRouteEnhancer::setEnhancers in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php \Drupal\Core\Routing\LazyRouteEnhancer::setEnhancers()

For each route, saves a list of applicable enhancers to the route.

Parameters

\Symfony\Component\Routing\RouteCollection $route_collection: A collection of routes to apply enhancer checks to.

File

core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php, line 59
Contains \Drupal\Core\Routing\LazyRouteEnhancer.

Class

LazyRouteEnhancer
A route enhancer which lazily loads route enhancers, depending on the route.

Namespace

Drupal\Core\Routing

Code

public function setEnhancers(RouteCollection $route_collection) {

  /** @var \Symfony\Component\Routing\Route $route **/
  foreach ($route_collection as $route_name => $route) {
    $service_ids = [];
    foreach ($this
      ->getEnhancers() as $service_id => $enhancer) {
      if (!$enhancer instanceof RouteEnhancerInterface || $enhancer
        ->applies($route)) {
        $service_ids[] = $service_id;
      }
    }
    if ($service_ids) {
      $route
        ->setOption('_route_enhancers', array_unique($service_ids));
    }
  }
}