3 namespace Drupal\layout_builder\Routing;
5 use Drupal\Core\ParamConverter\ParamConverterInterface;
6 use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
7 use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
8 use Symfony\Component\Routing\Route;
11 * Loads the section storage from the layout tempstore.
15 class LayoutTempstoreParamConverter implements ParamConverterInterface {
18 * The layout tempstore repository.
20 * @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
22 protected $layoutTempstoreRepository;
25 * The section storage manager.
27 * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
29 protected $sectionStorageManager;
32 * Constructs a new LayoutTempstoreParamConverter.
34 * @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
35 * The layout tempstore repository.
36 * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
37 * The section storage manager.
39 public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, SectionStorageManagerInterface $section_storage_manager) {
40 $this->layoutTempstoreRepository = $layout_tempstore_repository;
41 $this->sectionStorageManager = $section_storage_manager;
47 public function convert($value, $definition, $name, array $defaults) {
48 if (isset($defaults['section_storage_type']) && $this->sectionStorageManager->hasDefinition($defaults['section_storage_type'])) {
49 if ($section_storage = $this->sectionStorageManager->loadFromRoute($defaults['section_storage_type'], $value, $definition, $name, $defaults)) {
50 // Pass the plugin through the tempstore repository.
51 return $this->layoutTempstoreRepository->get($section_storage);
59 public function applies($definition, $name, Route $route) {
60 return !empty($definition['layout_builder_tempstore']);