RouteSubscriber.php in Layout Builder Restrictions 8.2
File
modules/layout_builder_restrictions_by_region/src/Routing/RouteSubscriber.php
View source
<?php
namespace Drupal\layout_builder_restrictions_by_region\Routing;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
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) {
if ($route_name = $entity_type
->get('field_ui_base_route')) {
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);
}
}
}
}