You are here

protected function RouteSubscriber::alterRoutes in Layout Builder Lock 8

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/RouteSubscriber.php, line 17

Class

RouteSubscriber
Add additional requirements for Layout builder routes.

Namespace

Drupal\layout_builder_lock\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $routes = [
    'layout_builder.move_block' => 'block_reorder',
    'layout_builder.move_block_form' => 'block_reorder',
    'layout_builder.choose_block' => 'block_add',
    'layout_builder.choose_inline_block' => 'block_add',
    'layout_builder.update_block' => 'block_config',
    'layout_builder.remove_block' => 'block_remove',
    'layout_builder.choose_section' => 'section_add',
    'layout_builder.configure_section' => 'section_edit',
    'layout_builder.remove_section' => 'section_remove',
  ];
  foreach ($routes as $route_name => $access) {
    if ($route = $collection
      ->get($route_name)) {
      $route
        ->setRequirement('_layout_builder_lock_access', $access);
    }
  }
}