3 namespace Drupal\entityqueue\Routing;
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Routing\RouteSubscriberBase;
7 use Drupal\Core\Routing\RoutingEvents;
8 use Symfony\Component\Routing\Route;
9 use Symfony\Component\Routing\RouteCollection;
12 * Subscriber for entityqueue routes.
14 class RouteSubscriber extends RouteSubscriberBase {
17 * The entity type manager service.
19 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21 protected $entityTypeManager;
24 * Constructs a new RouteSubscriber object.
26 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
27 * The entity type manager.
29 public function __construct(EntityTypeManagerInterface $entity_manager) {
30 $this->entityTypeManager = $entity_manager;
36 protected function alterRoutes(RouteCollection $collection) {
37 foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
38 // Try to get the route from the current collection.
39 $link_template = $entity_type->getLinkTemplate('canonical');
40 if (strpos($link_template, '/') !== FALSE) {
41 $base_path = '/' . $link_template;
44 if (!$entity_route = $collection->get("entity.$entity_type_id.canonical")) {
47 $base_path = $entity_route->getPath();
50 // Inherit admin route status from edit route, if exists.
52 $route_name = "entity.$entity_type_id.edit_form";
53 if ($edit_route = $collection->get($route_name)) {
54 $is_admin = (bool) $edit_route->getOption('_admin_route');
57 $path = $base_path . '/entityqueue';
62 '_controller' => '\Drupal\entityqueue\Controller\EntityQueueUIController::subqueueListForEntity',
63 'entity_type_id' => $entity_type_id,
64 '_title' => 'Entityqueues',
67 '_permission' => 'administer entityqueue+manipulate entityqueues+manipulate all entityqueues',
68 '_custom_access' => 'Drupal\entityqueue\Controller\EntityQueueUIController::access',
73 'type' => 'entity:' . $entity_type_id,
76 '_admin_route' => $is_admin,
79 $route_name = "entity.$entity_type_id.entityqueue";
80 $collection->add($route_name, $route);
88 public static function getSubscribedEvents() {
89 $events = parent::getSubscribedEvents();
91 // Should run after AdminRouteSubscriber so the routes can inherit admin
92 // status of the edit routes on entities. Therefore priority -210.
93 $events[RoutingEvents::ALTER] = ['onAlterRoutes', -210];