RouteSubscriber.php in Entityqueue 8
File
src/Routing/RouteSubscriber.php
View source
<?php
namespace Drupal\entityqueue\Routing;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityTypeManager = $entity_manager;
}
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
$link_template = $entity_type
->getLinkTemplate('canonical');
if (strpos($link_template, '/') !== FALSE) {
$base_path = '/' . $link_template;
}
else {
if (!($entity_route = $collection
->get("entity.{$entity_type_id}.canonical"))) {
continue;
}
$base_path = $entity_route
->getPath();
}
$is_admin = FALSE;
$route_name = "entity.{$entity_type_id}.edit_form";
if ($edit_route = $collection
->get($route_name)) {
$is_admin = (bool) $edit_route
->getOption('_admin_route');
}
$path = $base_path . '/entityqueue';
$route = new Route($path, [
'_controller' => '\\Drupal\\entityqueue\\Controller\\EntityQueueUIController::subqueueListForEntity',
'entity_type_id' => $entity_type_id,
'_title' => 'Entityqueues',
], [
'_permission' => 'administer entityqueue+manipulate entityqueues+manipulate all entityqueues',
'_custom_access' => 'Drupal\\entityqueue\\Controller\\EntityQueueUIController::access',
], [
'parameters' => [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
],
'_admin_route' => $is_admin,
]);
$route_name = "entity.{$entity_type_id}.entityqueue";
$collection
->add($route_name, $route);
}
}
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-210,
];
return $events;
}
}