You are here

protected function RouteSubscriber::alterRoutes in Entityqueue 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 36

Class

RouteSubscriber
Subscriber for entityqueue routes.

Namespace

Drupal\entityqueue\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {

    // Try to get the route from the current collection.
    $link_template = $entity_type
      ->getLinkTemplate('canonical');
    if (strpos($link_template, '/') !== FALSE) {
      $base_path = '/' . $link_template;
    }
    else {
      if (!($entity_route = $collection
        ->get("entity.{$entity_type_id}.canonical"))) {
        continue;
      }
      $base_path = $entity_route
        ->getPath();
    }

    // Inherit admin route status from edit route, if exists.
    $is_admin = FALSE;
    $route_name = "entity.{$entity_type_id}.edit_form";
    if ($edit_route = $collection
      ->get($route_name)) {
      $is_admin = (bool) $edit_route
        ->getOption('_admin_route');
    }
    $path = $base_path . '/entityqueue';
    $route = new Route($path, [
      '_controller' => '\\Drupal\\entityqueue\\Controller\\EntityQueueUIController::subqueueListForEntity',
      'entity_type_id' => $entity_type_id,
      '_title' => 'Entityqueues',
    ], [
      '_permission' => 'administer entityqueue+manipulate entityqueues+manipulate all entityqueues',
      '_custom_access' => 'Drupal\\entityqueue\\Controller\\EntityQueueUIController::access',
    ], [
      'parameters' => [
        $entity_type_id => [
          'type' => 'entity:' . $entity_type_id,
        ],
      ],
      '_admin_route' => $is_admin,
    ]);
    $route_name = "entity.{$entity_type_id}.entityqueue";
    $collection
      ->add($route_name, $route);
  }
}