RouteSubscriber.php in Display Suite 8.3
File
src/Routing/RouteSubscriber.php
View source
<?php
namespace Drupal\ds\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_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
$base_table = $entity_type
->getBaseTable();
if ($entity_type
->get('field_ui_base_route') && !empty($base_table)) {
if ($display = $entity_type
->getLinkTemplate('display')) {
$route = new Route($display, [
'_controller' => '\\Drupal\\ds\\Controller\\DsController::contextualTab',
'_title' => 'Manage display',
'entity_type_id' => $entity_type_id,
], [
'_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display',
], [
'_admin_route' => TRUE,
'_ds_entity_type_id' => $entity_type_id,
'parameters' => [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
],
]);
$collection
->add("entity.{$entity_type_id}.display", $route);
}
}
}
}
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
100,
];
return $events;
}
}