You are here

protected function RouteSubscriber::alterRoutes in Convert Bundles 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 38

Class

RouteSubscriber
Subscriber for convert_bundles routes.

Namespace

Drupal\convert_bundles\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $route = new Route("/{$entity_type_id}/{{$entity_type_id}}/convertbundles");
    $route
      ->addDefaults([
      '_controller' => '\\Drupal\\convert_bundles\\Controller\\EntityController::getEntity',
      '_title' => 'Convert Bundle',
    ])
      ->addRequirements([
      '_permission' => 'administer convert_bundles',
    ])
      ->setOption('_admin_route', TRUE)
      ->setOption('_convert_bundles_entity_type_id', $entity_type_id)
      ->setOption('parameters', [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
      ],
    ]);
    $collection
      ->add("entity.{$entity_type_id}.convert_bundles", $route);
  }
}