You are here

protected function TeamAppByNameRouteAlterSubscriber::alterRoutes in Apigee Edge 8

Alters existing routes for a specific collection.

Parameters

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

Overrides RouteSubscriberBase::alterRoutes

File

modules/apigee_edge_teams/src/Routing/TeamAppByNameRouteAlterSubscriber.php, line 46

Class

TeamAppByNameRouteAlterSubscriber
Changes the 'type' of the 'team_app' route parameter if 'team' is available.

Namespace

Drupal\apigee_edge_teams\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($collection as $id => $route) {
    if (strpos($id, 'entity.team_app') !== FALSE && in_array('team', $route
      ->compile()
      ->getPathVariables()) && in_array('app', $route
      ->compile()
      ->getPathVariables())) {
      $params = $route
        ->getOption('parameters') ?? [];
      NestedArray::setValue($params, [
        'team',
        'type',
      ], 'entity:team');
      NestedArray::setValue($params, [
        'app',
        'type',
      ], 'team_app_by_name');
      $route
        ->setOption('parameters', $params);
    }
  }
}