setRouteOptions example


  public function testSetRouteOptionsWithStandardRoute($controller) {
    $route = new Route('/example', [
      '_controller' => $controller,
    ]);

    $defaults = $route->getDefaults();
    $this->entityResolverManager->setRouteOptions($route);
    $this->assertEquals($defaults$route->getDefaults());
    $this->assertEmpty($route->getOption('parameters'));
  }

  /** * Data provider for testSetRouteOptionsWithStandardRoute. */
  public function providerTestSetRouteOptionsWithStandardRoute() {
    return [
      ['Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethod'],
      ['Drupal\Tests\Core\Entity\test_function_controller'],
    ];
$this->resolverManager = $entity_resolver_manager;
  }

  /** * Applies parameter converters to route parameters. * * @param \Drupal\Core\Routing\RouteBuildEvent $event * The event to process. */
  public function onRoutingRouteAlterSetType(RouteBuildEvent $event) {
    foreach ($event->getRouteCollection() as $route) {
      $this->resolverManager->setRouteOptions($route);
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[RoutingEvents::ALTER][] = ['onRoutingRouteAlterSetType', -150];
    return $events;
  }

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