You are here

protected function RouteSubscriber::alterRoutes in View Modes Display 8.2

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 47

Class

RouteSubscriber
Subscriber for View Mode Display routes.

Namespace

Drupal\view_modes_display\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if ($viewModes = $this->entityDisplayRepository
      ->getViewModes($entity_type_id)) {
      if ($route = $this
        ->getPreviewList($entity_type)) {
        $collection
          ->add("entity.{$entity_type_id}.vmd_preview_list", $route);
      }
      if ($route = $this
        ->getPreviewRenderRoute($entity_type)) {
        $collection
          ->add("entity.{$entity_type_id}.vmd_preview_render", $route);
      }
    }
  }
}