Skip to content
Snippets Groups Projects

Fix Layout translation form reports unsaved changes and becomes stale + call undefined method idDefaultTranslation()

2 files
+ 42
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 37
0
<?php
namespace Drupal\layout_builder_st\EventSubscriber;
use Drupal\layout_builder\Event\PrepareLayoutEvent;
use Drupal\layout_builder\EventSubscriber\PrepareLayout as CorePrepareLayout;
/**
* Overrides the core PrepareLayout event subscriber.
*/
class PrepareLayout extends CorePrepareLayout {
/**
* {@inheritdoc}
*/
public function onPrepareLayout(PrepareLayoutEvent $event) {
$section_storage = $event->getSectionStorage();
// If the layout is being edited in its source language, let core
// layout_builder do its standard handling of the event.
if (method_exists($section_storage, 'isDefaultTranslation')) {
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.
if ($this->layoutTempstoreRepository->has($section_storage)) {
$this->messenger->addWarning($this->t('You have unsaved changes.'));
}
}
}
Loading