diff --git a/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php b/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php index b44abadb60..b797b1c843 100644 --- a/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php +++ b/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php @@ -79,7 +79,7 @@ public function onPrepareLayout(PrepareLayoutEvent $event) { } } // Add storage to tempstore regardless of what the storage is. - $this->layoutTempstoreRepository->add($section_storage); + $this->layoutTempstoreRepository->set($section_storage, FALSE); } } diff --git a/core/modules/layout_builder/src/LayoutTempstoreRepository.php b/core/modules/layout_builder/src/LayoutTempstoreRepository.php index ac76cc0d8c..64615123d1 100644 --- a/core/modules/layout_builder/src/LayoutTempstoreRepository.php +++ b/core/modules/layout_builder/src/LayoutTempstoreRepository.php @@ -64,27 +64,11 @@ public function hasUnsavedChanges(SectionStorageInterface $section_storage) { /** * {@inheritdoc} */ - public function set(SectionStorageInterface $section_storage) { - if ($this->has($section_storage)) { - $key = $this->getKey($section_storage); - $this->getTempstore($section_storage)->set($key, [ - 'section_storage' => $section_storage, - 'has_unsaved_changes' => TRUE, - ]); - } - else { - $this->add($section_storage); - } - } - - /** - * {@inheritdoc} - */ - public function add(SectionStorageInterface $section_storage) { + public function set(SectionStorageInterface $section_storage, $has_unsaved_changes = TRUE) { $key = $this->getKey($section_storage); $this->getTempstore($section_storage)->set($key, [ 'section_storage' => $section_storage, - 'has_unsaved_changes' => FALSE, + 'has_unsaved_changes' => $has_unsaved_changes, ]); } diff --git a/core/modules/layout_builder/src/LayoutTempstoreRepositoryInterface.php b/core/modules/layout_builder/src/LayoutTempstoreRepositoryInterface.php index 6b851f733c..edcd7f9a72 100644 --- a/core/modules/layout_builder/src/LayoutTempstoreRepositoryInterface.php +++ b/core/modules/layout_builder/src/LayoutTempstoreRepositoryInterface.php @@ -27,16 +27,10 @@ public function get(SectionStorageInterface $section_storage); * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage to set in tempstore. + * @param bool $has_unsaved_changes + * (optional) Should be TRUE if $section_storage contains unsaved changes. */ - public function set(SectionStorageInterface $section_storage); - - /** - * Adds this section storage in tempstore. - * - * @param \Drupal\layout_builder\SectionStorageInterface $section_storage - * The section storage to added to tempstore. - */ - public function add(SectionStorageInterface $section_storage); + public function set(SectionStorageInterface $section_storage, $has_unsaved_changes = TRUE); /** * Checks for the existence of a tempstore version of a section storage.