You are here

class RouteSubscriber in Layout Builder Lock 8

Add additional requirements for Layout builder routes.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
layout_builder_lock.services.yml in ./layout_builder_lock.services.yml
layout_builder_lock.services.yml
1 service uses RouteSubscriber
layout_builder_perms.route_subscriber in ./layout_builder_lock.services.yml
Drupal\layout_builder_lock\Routing\RouteSubscriber

File

src/Routing/RouteSubscriber.php, line 12

Namespace

Drupal\layout_builder_lock\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  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);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -100,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase::getSubscribedEvents
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1