class LayoutSectionStorageParamConverter in Drupal 10
Loads the section storage from the routing defaults.
@internal Tagged services are internal.
Hierarchy
- class \Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter implements ParamConverterInterface
Expanded class hierarchy of LayoutSectionStorageParamConverter
1 file declares its use of LayoutSectionStorageParamConverter
- LayoutSectionStorageParamConverterTest.php in core/
modules/ layout_builder/ tests/ src/ Unit/ LayoutSectionStorageParamConverterTest.php
1 string reference to 'LayoutSectionStorageParamConverter'
- layout_builder.services.yml in core/
modules/ layout_builder/ layout_builder.services.yml - core/modules/layout_builder/layout_builder.services.yml
1 service uses LayoutSectionStorageParamConverter
- layout_builder.param_converter in core/
modules/ layout_builder/ layout_builder.services.yml - Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter
File
- core/
modules/ layout_builder/ src/ Routing/ LayoutSectionStorageParamConverter.php, line 15
Namespace
Drupal\layout_builder\RoutingView source
class LayoutSectionStorageParamConverter implements ParamConverterInterface {
/**
* The section storage manager.
*
* @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
*/
protected $sectionStorageManager;
/**
* Constructs a new LayoutSectionStorageParamConverter.
*
* @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
* The section storage manager.
*/
public function __construct(SectionStorageManagerInterface $section_storage_manager) {
$this->sectionStorageManager = $section_storage_manager;
}
/**
* {@inheritdoc}
*/
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.
return $this->sectionStorageManager
->load($type, $contexts);
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
return !empty($definition['layout_builder_section_storage']) || !empty($definition['layout_builder_tempstore']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LayoutSectionStorageParamConverter:: |
protected | property | The section storage manager. | |
LayoutSectionStorageParamConverter:: |
public | function |
Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface:: |
|
LayoutSectionStorageParamConverter:: |
public | function |
Converts path variables to their corresponding objects. Overrides ParamConverterInterface:: |
|
LayoutSectionStorageParamConverter:: |
public | function | Constructs a new LayoutSectionStorageParamConverter. |