You are here

class AdminRouteSubscriber in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php \Drupal\system\EventSubscriber\AdminRouteSubscriber

Adds the _admin_route option to each admin route.

Hierarchy

Expanded class hierarchy of AdminRouteSubscriber

1 string reference to 'AdminRouteSubscriber'
system.services.yml in core/modules/system/system.services.yml
core/modules/system/system.services.yml
1 service uses AdminRouteSubscriber
system.admin_path.route_subscriber in core/modules/system/system.services.yml
Drupal\system\EventSubscriber\AdminRouteSubscriber

File

core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php, line 17
Contains \Drupal\system\EventSubscriber\AdminRouteSubscriber.

Namespace

Drupal\system\EventSubscriber
View source
class AdminRouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($collection
      ->all() as $route) {
      if (strpos($route
        ->getPath(), '/admin') === 0 && !$route
        ->hasOption('_admin_route')) {
        $route
          ->setOption('_admin_route', TRUE);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = parent::getSubscribedEvents();

    // Use a higher priority than \Drupal\field_ui\Routing\RouteSubscriber or
    // \Drupal\views\EventSubscriber\RouteSubscriber to ensure we add the
    // option to their routes.
    // @todo https://www.drupal.org/node/2158571
    $events[RoutingEvents::ALTER] = array(
      'onAlterRoutes',
      -200,
    );
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminRouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
AdminRouteSubscriber::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