Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / token / src / Routing / RouteSubscriber.php
1 <?php
2
3 namespace Drupal\token\Routing;
4
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Routing\RouteSubscriberBase;
8 use Drupal\Core\Routing\RoutingEvents;
9 use Symfony\Component\Routing\Route;
10 use Symfony\Component\Routing\RouteCollection;
11
12 /**
13  * Subscriber for Devel routes.
14  */
15 class RouteSubscriber extends RouteSubscriberBase {
16
17   /**
18    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
19    */
20   protected $entityTypeManager;
21
22   /**
23    * @var \Drupal\Core\Extension\ModuleHandlerInterface
24    */
25   protected $moduleHandler;
26
27   public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
28     $this->entityTypeManager = $entity_type_manager;
29     $this->moduleHandler = $module_handler;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function alterRoutes(RouteCollection $collection) {
36     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
37       if ($devel_render = $entity_type->getLinkTemplate('token-devel')) {
38         $options = [
39           '_admin_route' => TRUE,
40           '_token_entity_type_id' => $entity_type_id,
41           'parameters' => [
42             $entity_type_id => [
43               'type' => 'entity:' . $entity_type_id,
44             ],
45           ],
46         ];
47
48         $route = new Route(
49           $devel_render,
50           [
51             '_controller' => '\Drupal\token\Controller\TokenDevelController::entityTokens',
52             '_title' => 'Devel Tokens',
53           ],
54           [
55             '_permission' => 'access devel information',
56             '_module_dependencies' => 'devel',
57           ],
58           $options
59         );
60
61         $collection->add("entity.$entity_type_id.token_devel", $route);
62       }
63     }
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public static function getSubscribedEvents() {
70     $events = parent::getSubscribedEvents();
71     $events[RoutingEvents::ALTER] = array('onAlterRoutes', 100);
72     return $events;
73   }
74
75 }