function DefaultsSectionStorage::buildRoutes
Same name in other branches
- 9 core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::buildRoutes()
- 8.9.x core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::buildRoutes()
- 10 core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::buildRoutes()
Overrides SectionStorageInterface::buildRoutes
File
-
core/
modules/ layout_builder/ src/ Plugin/ SectionStorage/ DefaultsSectionStorage.php, line 154
Class
- DefaultsSectionStorage
- Defines the 'defaults' section storage type.
Namespace
Drupal\layout_builder\Plugin\SectionStorageCode
public function buildRoutes(RouteCollection $collection) {
if (!\Drupal::moduleHandler()->moduleExists('field_ui')) {
return;
}
foreach ($this->getEntityTypes() as $entity_type_id => $entity_type) {
// Try to get the route from the current collection.
if (!($entity_route = $collection->get($entity_type->get('field_ui_base_route')))) {
continue;
}
$path = $entity_route->getPath() . '/display/{view_mode_name}/layout';
$defaults = [];
$defaults['entity_type_id'] = $entity_type_id;
// If the entity type has no bundles and it doesn't use {bundle} in its
// admin path, use the entity type.
if (!str_contains($path, '{bundle}')) {
if (!$entity_type->hasKey('bundle')) {
$defaults['bundle'] = $entity_type_id;
}
else {
$defaults['bundle_key'] = $entity_type->getBundleEntityType();
}
}
$requirements = [];
$requirements['_field_ui_view_mode_access'] = 'administer ' . $entity_type_id . ' display';
$options = $entity_route->getOptions();
$options['_admin_route'] = FALSE;
$this->buildLayoutRoutes($collection, $this->getPluginDefinition(), $path, $defaults, $requirements, $options, $entity_type_id, 'entity_view_display');
// Set field_ui.route_enhancer to run on the manage layout form.
if (isset($defaults['bundle_key'])) {
$collection->get("layout_builder.defaults.{$entity_type_id}.view")
->setOption('_field_ui', TRUE)
->setDefault('bundle', '');
}
$route_names = [
"entity.entity_view_display.{$entity_type_id}.default",
"entity.entity_view_display.{$entity_type_id}.view_mode",
];
foreach ($route_names as $route_name) {
if (!($route = $collection->get($route_name))) {
continue;
}
$route->addDefaults([
'section_storage_type' => $this->getStorageType(),
'section_storage' => '',
] + $defaults);
$parameters['section_storage']['layout_builder_tempstore'] = TRUE;
$parameters = NestedArray::mergeDeep($parameters, $route->getOption('parameters') ?: []);
$route->setOption('parameters', $parameters);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.