Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / entityqueue / src / Routing / RouteSubscriber.php
1 <?php
2
3 namespace Drupal\entityqueue\Routing;
4
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;
10
11 /**
12  * Subscriber for entityqueue routes.
13  */
14 class RouteSubscriber extends RouteSubscriberBase {
15
16   /**
17    * The entity type manager service.
18    *
19    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
20    */
21   protected $entityTypeManager;
22
23   /**
24    * Constructs a new RouteSubscriber object.
25    *
26    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
27    *   The entity type manager.
28    */
29   public function __construct(EntityTypeManagerInterface $entity_manager) {
30     $this->entityTypeManager = $entity_manager;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
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;
42       }
43       else {
44         if (!$entity_route = $collection->get("entity.$entity_type_id.canonical")) {
45           continue;
46         }
47         $base_path = $entity_route->getPath();
48       }
49
50       // Inherit admin route status from edit route, if exists.
51       $is_admin = FALSE;
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');
55       }
56
57       $path = $base_path . '/entityqueue';
58
59       $route = new Route(
60         $path,
61         [
62           '_controller' => '\Drupal\entityqueue\Controller\EntityQueueUIController::subqueueListForEntity',
63           'entity_type_id' => $entity_type_id,
64           '_title' => 'Entityqueues',
65         ],
66         [
67           '_permission' => 'administer entityqueue+manipulate entityqueues+manipulate all entityqueues',
68           '_custom_access' => 'Drupal\entityqueue\Controller\EntityQueueUIController::access',
69         ],
70         [
71           'parameters' => [
72             $entity_type_id => [
73               'type' => 'entity:' . $entity_type_id,
74             ],
75           ],
76           '_admin_route' => $is_admin,
77         ]
78       );
79       $route_name = "entity.$entity_type_id.entityqueue";
80       $collection->add($route_name, $route);
81
82     }
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public static function getSubscribedEvents() {
89     $events = parent::getSubscribedEvents();
90
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];
94
95     return $events;
96   }
97
98 }