setRouteParameterConverters example

->with($this->anything(), 'id', $this->anything())
      ->willReturn(TRUE);
    $this->manager->addConverter($converter, 'applied');

    $route = new Route($path);
    if ($parameters) {
      $route->setOption('parameters', $parameters);
    }
    $collection = new RouteCollection();
    $collection->add('test_route', $route);

    $this->manager->setRouteParameterConverters($collection);
    foreach ($collection as $route) {
      $result = $route->getOption('parameters');
      if ($expected) {
        $this->assertSame($expected$result['id']['converter']);
      }
      else {
        $this->assertNull($result);
      }
    }
  }

  
public function __construct(ParamConverterManagerInterface $param_converter_manager) {
    $this->paramConverterManager = $param_converter_manager;
  }

  /** * Applies parameter converters to route parameters. * * @param \Drupal\Core\Routing\RouteBuildEvent $event * The event to process. */
  public function onRoutingRouteAlterSetParameterConverters(RouteBuildEvent $event) {
    $this->paramConverterManager->setRouteParameterConverters($event->getRouteCollection());
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    // Run after \Drupal\system\EventSubscriber\AdminRouteSubscriber.     $events[RoutingEvents::ALTER][] = ['onRoutingRouteAlterSetParameterConverters', -220];
    return $events;
  }

}
Home | Imprint | This part of the site doesn't use cookies.