You are here

protected function RouteSubscriber::alterRoutes in Workspace 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 33

Class

RouteSubscriber
Subscriber for Workspace routes.

Namespace

Drupal\workspace\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($this->multiversionManager
    ->getEnabledEntityTypes() as $entity_type_id => $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('version-tree')) {
      $options = [
        '_admin_route' => TRUE,
        '_entity_type_id' => $entity_type_id,
        'parameters' => [
          $entity_type_id => [
            'type' => 'entity:' . $entity_type_id,
          ],
        ],
      ];
      if ($link_template = $entity_type
        ->getLinkTemplate('version-tree')) {
        $route = new Route($link_template, [
          '_controller' => '\\Drupal\\workspace\\Controller\\RevisionsController::revisions',
          '_title' => 'Revisions',
        ], [
          '_permission' => 'view_revision_trees',
        ], $options);

        // This will create new routes
        $collection
          ->add("entity.{$entity_type_id}.version_tree", $route);
      }
      if (($link_template = $entity_type
        ->getLinkTemplate('revision')) && empty($collection
        ->get("entity.{$entity_type_id}.revision"))) {
        unset($options['_admin_route']);
        $options['parameters']['entity_revision'] = [
          'type' => 'entity_revision:' . $entity_type_id,
        ];
        $route = new Route($link_template, [
          '_controller' => '\\Drupal\\workspace\\Controller\\RevisionController::view',
          '_title_callback' => '\\Drupal\\workspace\\Controller\\RevisionController::viewTitle',
        ], [
          '_permission' => 'view_revision_trees',
        ], $options);

        // This will create new routes (and override the revision
        // route for entity types that already has one).
        $collection
          ->add("entity.{$entity_type_id}.revision", $route);
      }
    }
  }
}