LayoutTempstoreParamConverter.php in Drupal 9
File
core/modules/layout_builder/src/Routing/LayoutTempstoreParamConverter.php
View source
<?php
namespace Drupal\layout_builder\Routing;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
use Symfony\Component\Routing\Route;
class LayoutTempstoreParamConverter implements ParamConverterInterface {
protected $layoutTempstoreRepository;
protected $sectionStorageManager;
public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, SectionStorageManagerInterface $section_storage_manager) {
$this->layoutTempstoreRepository = $layout_tempstore_repository;
$this->sectionStorageManager = $section_storage_manager;
}
public function convert($value, $definition, $name, array $defaults) {
if (!isset($defaults['section_storage_type']) || !$this->sectionStorageManager
->hasDefinition($defaults['section_storage_type'])) {
return NULL;
}
$type = $defaults['section_storage_type'];
$contexts = $this->sectionStorageManager
->loadEmpty($type)
->deriveContextsFromRoute($value, $definition, $name, $defaults);
if ($section_storage = $this->sectionStorageManager
->load($type, $contexts)) {
return $this->layoutTempstoreRepository
->get($section_storage);
}
}
public function applies($definition, $name, Route $route) {
return !empty($definition['layout_builder_tempstore']);
}
}