You are here

protected function RouteSubscriber::alterRoutes in Menu Admin per Menu 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 17

Class

RouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\menu_admin_per_menu\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $routes = $collection
    ->all();
  foreach ($routes as $route_name => $route) {
    switch ($route_name) {
      case 'entity.menu.collection':
        $route
          ->setDefaults([
          '_title' => $route
            ->getDefault('_title'),
          '_controller' => '\\Drupal\\menu_admin_per_menu\\Controller\\MenuAdminPerMenuController::menuOverviewPage',
        ]);
        $route
          ->setRequirements([
          '_custom_access' => '\\Drupal\\menu_admin_per_menu\\Access\\MenuAdminPerMenuAccess::menusOverviewAccess',
        ]);
        break;
      case 'entity.menu.edit_form':
      case 'entity.menu.add_link_form':
        $route
          ->setRequirements([
          '_custom_access' => '\\Drupal\\menu_admin_per_menu\\Access\\MenuAdminPerMenuAccess::menuAccess',
        ]);
        break;
      case 'menu_ui.link_edit':
      case 'menu_ui.link_reset':
        $route
          ->setRequirements([
          '_custom_access' => '\\Drupal\\menu_admin_per_menu\\Access\\MenuAdminPerMenuAccess::menuLinkAccess',
        ]);
        break;
      case 'entity.menu_link_content.canonical':
      case 'entity.menu_link_content.delete_form':
      case 'entity.menu_link_content.content_translation_overview':
      case 'entity.menu_link_content.content_translation_add':
      case 'entity.menu_link_content.content_translation_edit':
      case 'entity.menu_link_content.content_translation_delete':
        $route
          ->setRequirements([
          '_custom_access' => '\\Drupal\\menu_admin_per_menu\\Access\\MenuAdminPerMenuAccess::menuItemAccess',
        ]);
        break;
    }
  }
}