LayoutParagraphsLayoutTempstoreRepository.php in Layout Paragraphs 2.0.x
File
src/LayoutParagraphsLayoutTempstoreRepository.php
View source
<?php
namespace Drupal\layout_paragraphs;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
class LayoutParagraphsLayoutTempstoreRepository {
protected $tempStoreFactory;
public function __construct(PrivateTempStoreFactory $temp_store_factory) {
$this->tempStoreFactory = $temp_store_factory;
}
public function get(LayoutParagraphsLayout $layout_paragraphs_layout) {
$key = $this
->getStorageKey($layout_paragraphs_layout);
$tempstore_layout = $this
->getWithStorageKey($key);
if (empty($tempstore_layout)) {
$tempstore_layout = $this
->set($layout_paragraphs_layout);
}
return $tempstore_layout;
}
public function getWithStorageKey(string $key) {
return $this->tempStoreFactory
->get('layout_paragraphs')
->get($key);
}
public function set(LayoutParagraphsLayout $layout_paragraphs_layout) {
$key = $this
->getStorageKey($layout_paragraphs_layout);
$this->tempStoreFactory
->get('layout_paragraphs')
->set($key, $layout_paragraphs_layout);
return $layout_paragraphs_layout;
}
public function delete(LayoutParagraphsLayout $layout_paragraphs_layout) {
$key = $this
->getStorageKey($layout_paragraphs_layout);
$this->tempStoreFactory
->get('layout_paragraphs')
->delete($key);
}
public function getStorageKey(LayoutParagraphsLayout $layout_paragraphs_layout) {
return $layout_paragraphs_layout
->id();
}
}