You are here

public function OverridesSectionStorage::buildRoutes in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::buildRoutes()

Provides the routes needed for Layout Builder UI.

Allows the plugin to add or alter routes during the route building process. \Drupal\layout_builder\Routing\LayoutBuilderRoutesTrait is provided for the typical use case of building a standard Layout Builder UI.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection.

Overrides SectionStorageInterface::buildRoutes

See also

\Drupal\Core\Routing\RoutingEvents::ALTER

File

core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php, line 217

Class

OverridesSectionStorage
Defines the 'overrides' section storage type.

Namespace

Drupal\layout_builder\Plugin\SectionStorage

Code

public function buildRoutes(RouteCollection $collection) {
  foreach ($this
    ->getEntityTypes() as $entity_type_id => $entity_type) {

    // If the canonical route does not exist, do not provide any Layout
    // Builder UI routes for this entity type.
    if (!$collection
      ->get("entity.{$entity_type_id}.canonical")) {
      continue;
    }
    $defaults = [];
    $defaults['entity_type_id'] = $entity_type_id;

    // Retrieve the requirements from the canonical route.
    $requirements = $collection
      ->get("entity.{$entity_type_id}.canonical")
      ->getRequirements();
    $options = [];

    // Ensure that upcasting is run in the correct order.
    $options['parameters']['section_storage'] = [];
    $options['parameters'][$entity_type_id]['type'] = 'entity:' . $entity_type_id;
    $template = $entity_type
      ->getLinkTemplate('canonical') . '/layout';
    $this
      ->buildLayoutRoutes($collection, $this
      ->getPluginDefinition(), $template, $defaults, $requirements, $options, $entity_type_id, $entity_type_id);
  }
}