You are here

protected function RouteSubscriber::alterRoutes in Webform Views Integration 8.5

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/RouteSubscriber.php, line 39

Class

RouteSubscriber
Alter the routes in order to allow multiple views on the same route.

Namespace

Drupal\webform_views\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $view_route_names = $this->state
    ->get('views.view_route_names');
  foreach (webform_views_applicable_views() as $trio) {
    list($view_id, $display_id, $path) = $trio;
    $route_name = $view_route_names[$view_id . '.' . $display_id];
    if (($route = $collection
      ->get($route_name)) && ($webform_id = webform_views_webform_id_from_path($path))) {
      $route
        ->setPath($route
        ->getPath() . '/{webform}');
      $route
        ->setDefault('webform', $webform_id);
      $options = $route
        ->getOptions();
      $options['parameters']['webform']['type'] = 'entity:webform';
      $route
        ->setOptions($options);
    }
  }
}