You are here

class RouteSubscriber in Menu Admin per Menu 8

Listens to the dynamic route events.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
menu_admin_per_menu.services.yml in ./menu_admin_per_menu.services.yml
menu_admin_per_menu.services.yml
1 service uses RouteSubscriber
menu_admin_per_menu.route_subscriber in ./menu_admin_per_menu.services.yml
Drupal\menu_admin_per_menu\Routing\RouteSubscriber

File

src/Routing/RouteSubscriber.php, line 12

Namespace

Drupal\menu_admin_per_menu\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  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;
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Run after content_translation, which has priority -210.
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -220,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase::getSubscribedEvents
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1