core/modules/rest/rest.services.yml | 4 --- .../src/EventSubscriber/RestRouteSubscriber.php | 40 ---------------------- .../src/EventSubscriber/AdminRouteSubscriber.php | 20 +++++++++-- 3 files changed, 17 insertions(+), 47 deletions(-) diff --git a/core/modules/rest/rest.services.yml b/core/modules/rest/rest.services.yml index ebed915..869eb19 100644 --- a/core/modules/rest/rest.services.yml +++ b/core/modules/rest/rest.services.yml @@ -31,7 +31,3 @@ services: arguments: ['@router.builder'] tags: - { name: event_subscriber } - rest.route_subscriber: - class: Drupal\rest\EventSubscriber\RestRouteSubscriber - tags: - - { name: event_subscriber } diff --git a/core/modules/rest/src/EventSubscriber/RestRouteSubscriber.php b/core/modules/rest/src/EventSubscriber/RestRouteSubscriber.php deleted file mode 100644 index bd81370..0000000 --- a/core/modules/rest/src/EventSubscriber/RestRouteSubscriber.php +++ /dev/null @@ -1,40 +0,0 @@ -all() as $name => $route) { - // Removes the '_admin_route' route option from each REST route that had - // it added by \Drupal\system\EventSubscriber\AdminRouteSubscriber. - if (strpos($name, 'rest.') === 0 && $route->hasOption('_admin_route')) { - $route->setOption('_admin_route', FALSE); - } - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - $events = parent::getSubscribedEvents(); - - // Use a very low priority to run as late as possible. Especially use a - // lower priority than \Drupal\system\EventSubscriber\AdminRouteSubscriber. - $events[RoutingEvents::ALTER] = ['onAlterRoutes', -1000]; - - return $events; - } - -} diff --git a/core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php b/core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php index b83fe7e..ac2a47f 100644 --- a/core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php +++ b/core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php @@ -4,10 +4,11 @@ use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\Core\Routing\RoutingEvents; +use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; /** - * Adds the _admin_route option to each admin route. + * Adds the _admin_route option to each admin HTML route. */ class AdminRouteSubscriber extends RouteSubscriberBase { @@ -15,14 +16,27 @@ 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')) { + foreach ($collection->all() as $name => $route) { + if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route') && static::isHtmlRoute($route)) { $route->setOption('_admin_route', TRUE); } } } /** + * Whether the given route is a HTML route. + * + * @param \Symfony\Component\Routing\Route $route + * The route to inspect. + * + * @return bool + * Whether the given route is a HTML route. + */ + protected static function isHtmlRoute(Route $route) { + return !$route->hasRequirement('_format') || in_array('html', explode('|', $route->getRequirement('_format')), TRUE); + } + + /** * {@inheritdoc} */ public static function getSubscribedEvents() {