diff --git a/layout_builder_st.services.yml b/layout_builder_st.services.yml index 225ac7d..01fe9cc 100644 --- a/layout_builder_st.services.yml +++ b/layout_builder_st.services.yml @@ -22,3 +22,8 @@ services: plugin.manager.element_info: class: Drupal\layout_builder_st\ElementManager arguments: ['@container.namespaces', '@cache.discovery', '@cache_tags.invalidator', '@module_handler', '@theme.manager'] + layout_builder.element.prepare_layout: + class: Drupal\layout_builder_st\EventSubscriber\PrepareLayout + arguments: ['@layout_builder.tempstore_repository', '@messenger'] + tags: + - { name: event_subscriber } diff --git a/src/EventSubscriber/PrepareLayout.php b/src/EventSubscriber/PrepareLayout.php new file mode 100644 index 0000000..4789458 --- /dev/null +++ b/src/EventSubscriber/PrepareLayout.php @@ -0,0 +1,34 @@ +getSectionStorage(); + + // If the layout is being edited in its source language, let core + // layout_builder do its standard handling of the event. + if ($section_storage->isDefaultTranslation()) { + return parent::onPrepareLayout($event); + } + // If a symmetric translation is being edited, do not add the section + // storage to the tempstore. This can result in the symmetric translation + // getting stuck in the "you have unsaved changes" state after the Layout + // Builder form is visited, even if no changes are made. Just show the + // unsaved changes message if needed. + elseif ($this->layoutTempstoreRepository->has($section_storage)) { + $this->messenger->addWarning($this->t('You have unsaved changes.')); + } + } + +}