function LayoutTempstoreRepository::get

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/LayoutTempstoreRepository.php \Drupal\layout_builder\LayoutTempstoreRepository::get()
  2. 8.9.x core/modules/layout_builder/src/LayoutTempstoreRepository.php \Drupal\layout_builder\LayoutTempstoreRepository::get()
  3. 11.x core/modules/layout_builder/src/LayoutTempstoreRepository.php \Drupal\layout_builder\LayoutTempstoreRepository::get()

Gets the tempstore version of a section storage, if it exists.

@throw \UnexpectedValueException Thrown if a value exists, but is not a section storage.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage to check for in tempstore.

Return value

\Drupal\layout_builder\SectionStorageInterface Either the version of this section storage from tempstore, or the passed section storage if none exists.

Overrides LayoutTempstoreRepositoryInterface::get

File

core/modules/layout_builder/src/LayoutTempstoreRepository.php, line 39

Class

LayoutTempstoreRepository
Provides a mechanism for loading layouts from tempstore.

Namespace

Drupal\layout_builder

Code

public function get(SectionStorageInterface $section_storage) {
  $key = $this->getKey($section_storage);
  // Check if the storage is present in the static cache.
  if (isset($this->cache[$key])) {
    return $this->cache[$key];
  }
  $tempstore = $this->getTempstore($section_storage)
    ->get($key);
  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, $key));
    }
    // Set the storage in the static cache.
    $this->cache[$key] = $section_storage;
  }
  return $section_storage;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.