Issue #3425890 by amateescu, smustgrave, larowlan: Return early in \Drupal\layout_builder\InlineBlockEntityOperations::handlePreSave if the entity is syncing

merge-requests/6959/head
catch 2024-03-07 14:58:08 +00:00
parent a3b755e724
commit 44999a9a2e
2 changed files with 48 additions and 2 deletions

View File

@ -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

View File

@ -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());
}
}