Skip to content
Snippets Groups Projects
Commit 44999a9a authored by catch's avatar catch
Browse files

Issue #3425890 by amateescu, smustgrave, larowlan: Return early in...

Issue #3425890 by amateescu, smustgrave, larowlan: Return early in \Drupal\layout_builder\InlineBlockEntityOperations::handlePreSave if the entity is syncing
parent a3b755e7
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\SynchronizableInterface;
use Drupal\layout_builder\Plugin\Block\InlineBlock; use Drupal\layout_builder\Plugin\Block\InlineBlock;
use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface; use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -146,11 +147,13 @@ public function handleEntityDelete(EntityInterface $entity) { ...@@ -146,11 +147,13 @@ public function handleEntityDelete(EntityInterface $entity) {
* The parent entity. * The parent entity.
*/ */
public function handlePreSave(EntityInterface $entity) { public function handlePreSave(EntityInterface $entity) {
if (!$this->isLayoutCompatibleEntity($entity)) { if (($entity instanceof SynchronizableInterface && $entity->isSyncing())
|| !$this->isLayoutCompatibleEntity($entity)
) {
return; return;
} }
$duplicate_blocks = FALSE;
$duplicate_blocks = FALSE;
if ($sections = $this->getEntitySections($entity)) { if ($sections = $this->getEntitySections($entity)) {
if ($this->originalEntityUsesDefaultStorage($entity)) { if ($this->originalEntityUsesDefaultStorage($entity)) {
// This is a new override from a default and the blocks need to be // This is a new override from a default and the blocks need to be
......
<?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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment