Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / src / EventSubscriber / AdminRouteSubscriber.php
1 <?php
2
3 namespace Drupal\system\EventSubscriber;
4
5 use Drupal\Core\Routing\RouteSubscriberBase;
6 use Drupal\Core\Routing\RoutingEvents;
7 use Symfony\Component\Routing\RouteCollection;
8
9 /**
10  * Adds the _admin_route option to each admin route.
11  */
12 class AdminRouteSubscriber extends RouteSubscriberBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function alterRoutes(RouteCollection $collection) {
18     foreach ($collection->all() as $route) {
19       if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) {
20         $route->setOption('_admin_route', TRUE);
21       }
22     }
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public static function getSubscribedEvents() {
29     $events = parent::getSubscribedEvents();
30
31     // Use a lower priority than \Drupal\field_ui\Routing\RouteSubscriber or
32     // \Drupal\views\EventSubscriber\RouteSubscriber to ensure we add the option
33     // to their routes.
34     $events[RoutingEvents::ALTER] = ['onAlterRoutes', -200];
35
36     return $events;
37   }
38
39 }