blob: 777efab6b0c51731bcfe39593233cb21b1f4dae7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
namespace Drupal\system\EventSubscriber;
use Drupal\Core\Routing\RouteBuildEvent;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Alters routes to add necessary requirements.
*
* @see \Drupal\system\Access\SystemAdminMenuBlockAccessCheck
* @see \Drupal\system\Controller\SystemController::systemAdminMenuBlockPage()
*/
class AccessRouteAlterSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
$events[RoutingEvents::ALTER][] = 'accessAdminMenuBlockPage';
return $events;
}
/**
* Adds requirements to some System Controller routes.
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The event to process.
*/
public function accessAdminMenuBlockPage(RouteBuildEvent $event) {
$routes = $event->getRouteCollection();
foreach ($routes as $route) {
// Do not use a leading slash when comparing to the _controller string
// because the leading slash in a fully-qualified method name is optional.
if ($route->hasDefault('_controller')) {
switch (ltrim($route->getDefault('_controller'), '\\')) {
case 'Drupal\system\Controller\SystemController::systemAdminMenuBlockPage':
$route->setRequirement('_access_admin_menu_block_page', 'TRUE');
break;
case 'Drupal\system\Controller\SystemController::overview':
$route->setRequirement('_access_admin_overview_page', 'TRUE');
break;
}
}
}
}
}
|