3 namespace Drupal\devel\Routing;
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
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 * @see \Drupal\devel\Controller\EntityDebugController
16 * @see \Drupal\devel\Plugin\Derivative\DevelLocalTask
18 class RouteSubscriber extends RouteSubscriberBase {
21 * The entity type manager service.
23 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
25 protected $entityTypeManager;
28 * Constructs a new RouteSubscriber object.
30 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
31 * The entity type manager.
33 public function __construct(EntityTypeManagerInterface $entity_manager) {
34 $this->entityTypeManager = $entity_manager;
40 protected function alterRoutes(RouteCollection $collection) {
41 foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
42 if ($route = $this->getEntityLoadRoute($entity_type)) {
43 $collection->add("entity.$entity_type_id.devel_load", $route);
45 if ($route = $this->getEntityRenderRoute($entity_type)) {
46 $collection->add("entity.$entity_type_id.devel_render", $route);
48 if ($route = $this->getEntityTypeDefinitionRoute($entity_type)) {
49 $collection->add("entity.$entity_type_id.devel_definition", $route);
55 * Gets the entity load route.
57 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
60 * @return \Symfony\Component\Routing\Route|null
61 * The generated route, if available.
63 protected function getEntityLoadRoute(EntityTypeInterface $entity_type) {
64 if ($devel_load = $entity_type->getLinkTemplate('devel-load')) {
65 $entity_type_id = $entity_type->id();
66 $route = new Route($devel_load);
69 '_controller' => '\Drupal\devel\Controller\EntityDebugController::entityLoad',
70 '_title' => 'Devel Load',
73 '_permission' => 'access devel information',
75 ->setOption('_admin_route', TRUE)
76 ->setOption('_devel_entity_type_id', $entity_type_id)
77 ->setOption('parameters', [
78 $entity_type_id => ['type' => 'entity:' . $entity_type_id],
86 * Gets the entity render route.
88 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
91 * @return \Symfony\Component\Routing\Route|null
92 * The generated route, if available.
94 protected function getEntityRenderRoute(EntityTypeInterface $entity_type) {
95 if ($devel_render = $entity_type->getLinkTemplate('devel-render')) {
96 $entity_type_id = $entity_type->id();
97 $route = new Route($devel_render);
100 '_controller' => '\Drupal\devel\Controller\EntityDebugController::entityRender',
101 '_title' => 'Devel Render',
104 '_permission' => 'access devel information'
106 ->setOption('_admin_route', TRUE)
107 ->setOption('_devel_entity_type_id', $entity_type_id)
108 ->setOption('parameters', [
109 $entity_type_id => ['type' => 'entity:' . $entity_type_id],
117 * Gets the entity type definition route.
119 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
122 * @return \Symfony\Component\Routing\Route|null
123 * The generated route, if available.
125 protected function getEntityTypeDefinitionRoute(EntityTypeInterface $entity_type) {
126 if ($devel_definition = $entity_type->getLinkTemplate('devel-definition')) {
127 $entity_type_id = $entity_type->id();
128 $route = new Route($devel_definition);
131 '_controller' => '\Drupal\devel\Controller\EntityDebugController::entityTypeDefinition',
132 '_title' => 'Entity type definition',
135 '_permission' => 'access devel information'
137 ->setOption('_admin_route', TRUE)
138 ->setOption('_devel_entity_type_id', $entity_type_id)
139 ->setOption('parameters', [
140 $entity_type_id => ['type' => 'entity:' . $entity_type_id],
150 public static function getSubscribedEvents() {
151 $events = parent::getSubscribedEvents();
152 $events[RoutingEvents::ALTER] = ['onAlterRoutes', 100];