diff core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
line wrap: on
line diff
--- a/core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php	Mon Apr 23 09:33:26 2018 +0100
+++ b/core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php	Mon Apr 23 09:46:53 2018 +0100
@@ -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 {
 
@@ -16,7 +17,7 @@
    */
   protected function alterRoutes(RouteCollection $collection) {
     foreach ($collection->all() as $route) {
-      if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) {
+      if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route') && static::isHtmlRoute($route)) {
         $route->setOption('_admin_route', TRUE);
       }
     }
@@ -36,4 +37,19 @@
     return $events;
   }
 
+  /**
+   * Determines whether the given route is a HTML route.
+   *
+   * @param \Symfony\Component\Routing\Route $route
+   *   The route to analyze.
+   *
+   * @return bool
+   *   TRUE if HTML is a valid format for this route.
+   */
+  protected static function isHtmlRoute(Route $route) {
+    // If a route has no explicit format, then HTML is valid.
+    $format = $route->hasRequirement('_format') ? explode('|', $route->getRequirement('_format')) : ['html'];
+    return in_array('html', $format, TRUE);
+  }
+
 }