public function LayoutTempstoreParamConverter::convert in Drupal 9
Same name and namespace in other branches
- 8 core/modules/layout_builder/src/Routing/LayoutTempstoreParamConverter.php \Drupal\layout_builder\Routing\LayoutTempstoreParamConverter::convert()
Converts path variables to their corresponding objects.
Parameters
mixed $value: The raw value.
mixed $definition: The parameter definition provided in the route options.
string $name: The name of the parameter.
array $defaults: The route defaults array.
Return value
mixed|null The converted parameter value.
Overrides ParamConverterInterface::convert
File
- core/
modules/ layout_builder/ src/ Routing/ LayoutTempstoreParamConverter.php, line 48
Class
- LayoutTempstoreParamConverter
- Loads the section storage from the layout tempstore.
Namespace
Drupal\layout_builder\RoutingCode
public function convert($value, $definition, $name, array $defaults) {
// If no section storage type is specified or if it is invalid, return.
if (!isset($defaults['section_storage_type']) || !$this->sectionStorageManager
->hasDefinition($defaults['section_storage_type'])) {
return NULL;
}
$type = $defaults['section_storage_type'];
// Load an empty instance and derive the available contexts.
$contexts = $this->sectionStorageManager
->loadEmpty($type)
->deriveContextsFromRoute($value, $definition, $name, $defaults);
// Attempt to load a full instance based on the context.
if ($section_storage = $this->sectionStorageManager
->load($type, $contexts)) {
// Pass the plugin through the tempstore repository.
return $this->layoutTempstoreRepository
->get($section_storage);
}
}