Chris@0: serviceIds = $service_ids; Chris@0: } Chris@0: Chris@0: /** Chris@0: * For each route, saves a list of applicable enhancers to the route. Chris@0: * Chris@0: * @param \Symfony\Component\Routing\RouteCollection $route_collection Chris@0: * A collection of routes to apply enhancer checks to. Chris@0: */ Chris@0: public function setEnhancers(RouteCollection $route_collection) { Chris@0: /** @var \Symfony\Component\Routing\Route $route **/ Chris@0: foreach ($route_collection as $route_name => $route) { Chris@0: $service_ids = []; Chris@0: foreach ($this->getEnhancers() as $service_id => $enhancer) { Chris@0: if ((!$enhancer instanceof RouteEnhancerInterface) || $enhancer->applies($route)) { Chris@0: $service_ids[] = $service_id; Chris@0: } Chris@0: } Chris@0: if ($service_ids) { Chris@0: $route->setOption('_route_enhancers', array_unique($service_ids)); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * For each route, gets a list of applicable enhancer to the route. Chris@0: * Chris@0: * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]|\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface[] Chris@0: */ Chris@0: protected function getEnhancers() { Chris@0: if (!isset($this->enhancers)) { Chris@0: foreach ($this->serviceIds as $service_id) { Chris@0: $this->enhancers[$service_id] = $this->container->get($service_id); Chris@0: } Chris@0: } Chris@0: return $this->enhancers; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function enhance(array $defaults, Request $request) { Chris@0: /** @var \Symfony\Component\Routing\Route $route */ Chris@0: $route = $defaults[RouteObjectInterface::ROUTE_OBJECT]; Chris@0: Chris@0: $enhancer_ids = $route->getOption('_route_enhancers'); Chris@0: Chris@0: if (isset($enhancer_ids)) { Chris@0: foreach ($enhancer_ids as $enhancer_id) { Chris@0: $defaults = $this->container->get($enhancer_id)->enhance($defaults, $request); Chris@0: } Chris@0: } Chris@0: Chris@0: return $defaults; Chris@0: } Chris@0: Chris@0: }