From 44999a9a2e105aa40d8468c0e7f44f8986a989ab Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 7 Mar 2024 14:58:08 +0000 Subject: [PATCH] Issue #3425890 by amateescu, smustgrave, larowlan: Return early in \Drupal\layout_builder\InlineBlockEntityOperations::handlePreSave if the entity is syncing --- .../src/InlineBlockEntityOperations.php | 7 ++- .../Unit/InlineBlockEntityOperationsTest.php | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 core/modules/layout_builder/tests/src/Unit/InlineBlockEntityOperationsTest.php diff --git a/core/modules/layout_builder/src/InlineBlockEntityOperations.php b/core/modules/layout_builder/src/InlineBlockEntityOperations.php index 5b11bbe6748..0007b9b3baa 100644 --- a/core/modules/layout_builder/src/InlineBlockEntityOperations.php +++ b/core/modules/layout_builder/src/InlineBlockEntityOperations.php @@ -6,6 +6,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\RevisionableInterface; +use Drupal\Core\Entity\SynchronizableInterface; use Drupal\layout_builder\Plugin\Block\InlineBlock; use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -146,11 +147,13 @@ class InlineBlockEntityOperations implements ContainerInjectionInterface { * The parent entity. */ public function handlePreSave(EntityInterface $entity) { - if (!$this->isLayoutCompatibleEntity($entity)) { + if (($entity instanceof SynchronizableInterface && $entity->isSyncing()) + || !$this->isLayoutCompatibleEntity($entity) + ) { return; } - $duplicate_blocks = FALSE; + $duplicate_blocks = FALSE; if ($sections = $this->getEntitySections($entity)) { if ($this->originalEntityUsesDefaultStorage($entity)) { // This is a new override from a default and the blocks need to be diff --git a/core/modules/layout_builder/tests/src/Unit/InlineBlockEntityOperationsTest.php b/core/modules/layout_builder/tests/src/Unit/InlineBlockEntityOperationsTest.php new file mode 100644 index 00000000000..5a619ff6f73 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Unit/InlineBlockEntityOperationsTest.php @@ -0,0 +1,43 @@ +prophesize(SynchronizableInterface::class); + $entity->isSyncing()->willReturn(TRUE); + + $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); + $inline_block_usage = $this->prophesize(InlineBlockUsageInterface::class); + $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class); + $section_storage_manager->findByContext()->shouldNotBeCalled(); + + $inline_block_entity_operations = new InlineBlockEntityOperations( + $entity_type_manager->reveal(), + $inline_block_usage->reveal(), + $section_storage_manager->reveal() + ); + $inline_block_entity_operations->handlePreSave($entity->reveal()); + } + +}