You are here

protected function RouteSubscriber::alterRoutes in Color API 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 16

Class

RouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\colorapi\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $colorapi_color_entity_routes = [
    'entity.colorapi_color.collection',
    'entity.colorapi_color.add_form',
    'entity.colorapi_color.edit_form',
    'entity.colorapi_color.delete_form',
  ];
  foreach ($colorapi_color_entity_routes as $route_name) {
    if ($route = $collection
      ->get($route_name)) {
      $color_entity_enabled = \Drupal::config('colorapi.settings')
        ->get('enable_color_entity');
      if (!$color_entity_enabled) {
        $collection
          ->remove($route_name);
      }
    }
  }
}