Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
2 | 2 |
3 namespace Drupal\system\EventSubscriber; | 3 namespace Drupal\system\EventSubscriber; |
4 | 4 |
5 use Drupal\Core\Routing\RouteSubscriberBase; | 5 use Drupal\Core\Routing\RouteSubscriberBase; |
6 use Drupal\Core\Routing\RoutingEvents; | 6 use Drupal\Core\Routing\RoutingEvents; |
7 use Symfony\Component\Routing\Route; | |
7 use Symfony\Component\Routing\RouteCollection; | 8 use Symfony\Component\Routing\RouteCollection; |
8 | 9 |
9 /** | 10 /** |
10 * Adds the _admin_route option to each admin route. | 11 * Adds the _admin_route option to each admin HTML route. |
11 */ | 12 */ |
12 class AdminRouteSubscriber extends RouteSubscriberBase { | 13 class AdminRouteSubscriber extends RouteSubscriberBase { |
13 | 14 |
14 /** | 15 /** |
15 * {@inheritdoc} | 16 * {@inheritdoc} |
16 */ | 17 */ |
17 protected function alterRoutes(RouteCollection $collection) { | 18 protected function alterRoutes(RouteCollection $collection) { |
18 foreach ($collection->all() as $route) { | 19 foreach ($collection->all() as $route) { |
19 if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) { | 20 if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route') && static::isHtmlRoute($route)) { |
20 $route->setOption('_admin_route', TRUE); | 21 $route->setOption('_admin_route', TRUE); |
21 } | 22 } |
22 } | 23 } |
23 } | 24 } |
24 | 25 |
34 $events[RoutingEvents::ALTER] = ['onAlterRoutes', -200]; | 35 $events[RoutingEvents::ALTER] = ['onAlterRoutes', -200]; |
35 | 36 |
36 return $events; | 37 return $events; |
37 } | 38 } |
38 | 39 |
40 /** | |
41 * Determines whether the given route is a HTML route. | |
42 * | |
43 * @param \Symfony\Component\Routing\Route $route | |
44 * The route to analyze. | |
45 * | |
46 * @return bool | |
47 * TRUE if HTML is a valid format for this route. | |
48 */ | |
49 protected static function isHtmlRoute(Route $route) { | |
50 // If a route has no explicit format, then HTML is valid. | |
51 $format = $route->hasRequirement('_format') ? explode('|', $route->getRequirement('_format')) : ['html']; | |
52 return in_array('html', $format, TRUE); | |
53 } | |
54 | |
39 } | 55 } |