class RouteSubscriber in Layout Builder Restrictions 8.2
Same name in this branch
- 8.2 src/Routing/RouteSubscriber.php \Drupal\layout_builder_restrictions\Routing\RouteSubscriber
- 8.2 modules/layout_builder_restrictions_by_region/src/Routing/RouteSubscriber.php \Drupal\layout_builder_restrictions_by_region\Routing\RouteSubscriber
Subscriber for Layout Builder Restrictions By Region routes.
Adapted from: Drupal\field_ui\Routing\RouteSubscriber.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\layout_builder_restrictions_by_region\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
- layout_builder_restrictions_by_region.services.yml in modules/
layout_builder_restrictions_by_region/ layout_builder_restrictions_by_region.services.yml - modules/layout_builder_restrictions_by_region/layout_builder_restrictions_by_region.services.yml
1 service uses RouteSubscriber
- layout_builder_restrictions_by_region.route_subscriber in modules/
layout_builder_restrictions_by_region/ layout_builder_restrictions_by_region.services.yml - Drupal\layout_builder_restrictions_by_region\Routing\RouteSubscriber
File
- modules/
layout_builder_restrictions_by_region/ src/ Routing/ RouteSubscriber.php, line 15
Namespace
Drupal\layout_builder_restrictions_by_region\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a RouteSubscriber object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($route_name = $entity_type
->get('field_ui_base_route')) {
// Try to get the route from the current collection.
if (!$collection
->get($route_name)) {
continue;
}
$route = new Route("/admin/layout-builder-restrictions/layout-builder-restrictions-by-region/{$entity_type_id}/allowed-blocks-form", [
'_form' => '\\Drupal\\layout_builder_restrictions_by_region\\Form\\AllowedBlocksForm',
'_title' => 'Allowed Blocks',
], [
'_permission' => 'administer ' . $entity_type_id . ' display',
]);
$collection
->add("layout_builder_restrictions_by_region.{$entity_type_id}_allowed_blocks", $route);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The entity type manager service. | |
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public | function | Constructs a RouteSubscriber object. | |
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 |