You are here

protected function TeamContextSwitcherRouteAlterSubscriber::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/TeamContextSwitcherRouteAlterSubscriber.php, line 37

Class

TeamContextSwitcherRouteAlterSubscriber
Adds the _apigee_team_route option to developer (user) routes.

Namespace

Drupal\apigee_edge_teams\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($collection as $id => $route) {

    // Add a corresponding team route if the team route defines a
    // corresponding developer route.
    if (($developer_route_id = $route
      ->getOption(TeamContextManagerInterface::DEVELOPER_ROUTE_OPTION_NAME)) && ($developer_route = $collection
      ->get($developer_route_id)) && empty($developer_route
      ->getOption(TeamContextManagerInterface::TEAM_ROUTE_OPTION_NAME))) {
      $developer_route
        ->setOption(TeamContextManagerInterface::TEAM_ROUTE_OPTION_NAME, $id);
    }
  }
}