You are here

protected function RouteSubscriber::alterRoutes in Organic groups 8

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 66

Class

RouteSubscriber
Route subscriber for OG related routes.

Namespace

Drupal\og\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if (!$entity_type
      ->hasLinkTemplate('canonical')) {

      // Entity type doesn't have a canonical route.
      continue;
    }
    if (!($og_admin_path = $entity_type
      ->getLinkTemplate('og-admin-routes'))) {

      // Entity type doesn't have the link template defined.
      continue;
    }
    $entity_type_id = $entity_type
      ->id();
    $route_name = "entity.{$entity_type_id}.og_admin_routes";
    $route = new Route($og_admin_path);
    $route
      ->addDefaults([
      '_controller' => '\\Drupal\\og\\Controller\\OgAdminRoutesController::overview',
      '_title' => 'Group management',
    ])
      ->addRequirements([
      '_og_user_access_group' => OgAccess::ADMINISTER_GROUP_PERMISSION,
    ])
      ->setOption('parameters', [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
      ],
    ])
      ->setOption('_og_entity_type_id', $entity_type_id)
      ->setOption('_admin_route', TRUE);
    $collection
      ->add($route_name, $route);

    // Add the routes defined in the event subscribers.
    $this
      ->createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, $collection);
  }
}