You are here

public function RouteSubscriber::alterRoutes in Layout Builder Restrictions 8.2

Same name in this branch
  1. 8.2 src/Routing/RouteSubscriber.php \Drupal\layout_builder_restrictions\Routing\RouteSubscriber::alterRoutes()
  2. 8.2 modules/layout_builder_restrictions_by_region/src/Routing/RouteSubscriber.php \Drupal\layout_builder_restrictions_by_region\Routing\RouteSubscriber::alterRoutes()

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 16

Class

RouteSubscriber
Override the controller for layout_builder.move_block.

Namespace

Drupal\layout_builder_restrictions\Routing

Code

public function alterRoutes(RouteCollection $collection) {
  if ($route = $collection
    ->get('layout_builder.move_block')) {
    $defaults = $route
      ->getDefaults();
    $defaults['_controller'] = '\\Drupal\\layout_builder_restrictions\\Controller\\MoveBlockController::build';
    $route
      ->setDefaults($defaults);
  }
  if ($route = $collection
    ->get('layout_builder.move_block_form')) {

    // Provide validation to the Layout Builder MoveBlock form.
    $route
      ->setDefault('_form', '\\Drupal\\layout_builder_restrictions\\Form\\MoveBlockForm');
  }

  // Add inline block filtering to parent class
  // Drupal\layout_builder\Controller\ChooseBlockController.
  if ($route = $collection
    ->get('layout_builder.choose_block')) {
    $defaults = $route
      ->getDefaults();
    $defaults['_controller'] = '\\Drupal\\layout_builder_restrictions\\Controller\\ChooseBlockController::build';
    $route
      ->setDefaults($defaults);
  }
  if ($route = $collection
    ->get('layout_builder.choose_inline_block')) {
    $defaults = $route
      ->getDefaults();
    $defaults['_controller'] = '\\Drupal\\layout_builder_restrictions\\Controller\\ChooseBlockController::inlineBlockList';
    $route
      ->setDefaults($defaults);
  }
}