class RouteSubscriber in Block Content Permissions 8
Listens to the dynamic route events.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\block_content_permissions\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 12
Namespace
Drupal\block_content_permissions\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* The AccessControlHandler class name.
*
* @var string
*/
private $accessControlHandlerClassName = 'Drupal\\block_content_permissions\\AccessControlHandler';
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
// Change access callback for the block content type pages.
$routeNames = [
'entity.block_content_type.collection',
'block_content.type_add',
];
foreach ($routeNames as $name) {
if ($route = $collection
->get($name)) {
$route
->addRequirements([
'_custom_access' => $this->accessControlHandlerClassName . '::blockContentTypeAdministerAccess',
]);
// Remove required "administer blocks" permission.
$this
->removePermissionRequirement($route);
}
}
/* Change access callback for the block content collection page. */
/* "entity.block_content.collection" route name does not work. */
// Change access and controller callback for the block content add page.
if ($route = $collection
->get('block_content.add_page')) {
$route
->addRequirements([
'_custom_access' => $this->accessControlHandlerClassName . '::blockContentAddPageAccess',
]);
$route
->setDefault('_controller', 'Drupal\\block_content_permissions\\Controller\\BlockContentPermissionsAddPageController::add');
// Remove required "administer blocks" permission.
$this
->removePermissionRequirement($route);
}
// Change access callback for the block content add forms.
if ($route = $collection
->get('block_content.add_form')) {
$route
->addRequirements([
'_custom_access' => $this->accessControlHandlerClassName . '::blockContentAddFormAccess',
]);
// Remove required "administer blocks" permission.
$this
->removePermissionRequirement($route);
}
}
/**
* Remove required "administer blocks" permission from route.
*
* @param \Symfony\Component\Routing\Route $route
* The Route object.
*/
private function removePermissionRequirement(Route $route) {
if ($route
->hasRequirement('_permission')) {
$requirements = $route
->getRequirements();
unset($requirements['_permission']);
$route
->setRequirements($requirements);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
private | property | The AccessControlHandler class name. | |
RouteSubscriber:: |
public | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
private | function | Remove required "administer blocks" permission from route. | |
RouteSubscriberBase:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | 5 |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |