X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Flayout_builder%2Fsrc%2FLayoutTempstoreRepository.php;fp=web%2Fcore%2Fmodules%2Flayout_builder%2Fsrc%2FLayoutTempstoreRepository.php;h=39725afc7e20068e9d25fdea0af447d0c32c117f;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/core/modules/layout_builder/src/LayoutTempstoreRepository.php b/web/core/modules/layout_builder/src/LayoutTempstoreRepository.php new file mode 100644 index 000000000..39725afc7 --- /dev/null +++ b/web/core/modules/layout_builder/src/LayoutTempstoreRepository.php @@ -0,0 +1,78 @@ +tempStoreFactory = $temp_store_factory; + } + + /** + * {@inheritdoc} + */ + public function get(SectionStorageInterface $section_storage) { + $id = $section_storage->getStorageId(); + $tempstore = $this->getTempstore($section_storage)->get($id); + if (!empty($tempstore['section_storage'])) { + $storage_type = $section_storage->getStorageType(); + $section_storage = $tempstore['section_storage']; + + if (!($section_storage instanceof SectionStorageInterface)) { + throw new \UnexpectedValueException(sprintf('The entry with storage type "%s" and ID "%s" is invalid', $storage_type, $id)); + } + } + return $section_storage; + } + + /** + * {@inheritdoc} + */ + public function set(SectionStorageInterface $section_storage) { + $id = $section_storage->getStorageId(); + $this->getTempstore($section_storage)->set($id, ['section_storage' => $section_storage]); + } + + /** + * {@inheritdoc} + */ + public function delete(SectionStorageInterface $section_storage) { + $id = $section_storage->getStorageId(); + $this->getTempstore($section_storage)->delete($id); + } + + /** + * Gets the shared tempstore. + * + * @param \Drupal\layout_builder\SectionStorageInterface $section_storage + * The section storage. + * + * @return \Drupal\Core\TempStore\SharedTempStore + * The tempstore. + */ + protected function getTempstore(SectionStorageInterface $section_storage) { + $collection = 'layout_builder.section_storage.' . $section_storage->getStorageType(); + return $this->tempStoreFactory->get($collection); + } + +}