3 namespace Drupal\token\Routing;
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;
13 * Subscriber for Devel routes.
15 class RouteSubscriber extends RouteSubscriberBase {
18 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
20 protected $entityTypeManager;
23 * @var \Drupal\Core\Extension\ModuleHandlerInterface
25 protected $moduleHandler;
27 public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
28 $this->entityTypeManager = $entity_type_manager;
29 $this->moduleHandler = $module_handler;
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')) {
39 '_admin_route' => TRUE,
40 '_token_entity_type_id' => $entity_type_id,
43 'type' => 'entity:' . $entity_type_id,
51 '_controller' => '\Drupal\token\Controller\TokenDevelController::entityTokens',
52 '_title' => 'Devel Tokens',
55 '_permission' => 'access devel information',
56 '_module_dependencies' => 'devel',
61 $collection->add("entity.$entity_type_id.token_devel", $route);
69 public static function getSubscribedEvents() {
70 $events = parent::getSubscribedEvents();
71 $events[RoutingEvents::ALTER] = array('onAlterRoutes', 100);