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