From 44999a9a2e105aa40d8468c0e7f44f8986a989ab Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> 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 5b11bbe67483..0007b9b3baab 100644 --- a/core/modules/layout_builder/src/InlineBlockEntityOperations.php +++ b/core/modules/layout_builder/src/InlineBlockEntityOperations.php @@ -6,6 +6,7 @@ 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 @@ public function handleEntityDelete(EntityInterface $entity) { * 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 000000000000..5a619ff6f734 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Unit/InlineBlockEntityOperationsTest.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\layout_builder\Unit; + +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\SynchronizableInterface; +use Drupal\layout_builder\InlineBlockEntityOperations; +use Drupal\layout_builder\InlineBlockUsageInterface; +use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface; +use Drupal\Tests\UnitTestCase; + +/** + * @coversDefaultClass \Drupal\layout_builder\InlineBlockEntityOperations + * + * @group layout_builder + */ +class InlineBlockEntityOperationsTest extends UnitTestCase { + + /** + * Tests calling handlePreSave() with an entity that is syncing. + * + * @covers ::handlePreSave + */ + public function testPreSaveWithSyncingEntity(): void { + $entity = $this->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()); + } + +} -- GitLab