Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / layout_builder / src / Routing / LayoutTempstoreParamConverter.php
diff --git a/web/core/modules/layout_builder/src/Routing/LayoutTempstoreParamConverter.php b/web/core/modules/layout_builder/src/Routing/LayoutTempstoreParamConverter.php
new file mode 100644 (file)
index 0000000..263b767
--- /dev/null
@@ -0,0 +1,63 @@
+<?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;
+
+/**
+ * Loads the section storage from the layout tempstore.
+ *
+ * @internal
+ */
+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 (isset($defaults['section_storage_type']) && $this->sectionStorageManager->hasDefinition($defaults['section_storage_type'])) {
+      if ($section_storage = $this->sectionStorageManager->loadFromRoute($defaults['section_storage_type'], $value, $definition, $name, $defaults)) {
+        // 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']);
+  }
+
+}