diff --git a/core/PATCHES.txt b/core/PATCHES.txt index 11d2d124..d3b6bfb1 100644 --- a/core/PATCHES.txt +++ b/core/PATCHES.txt @@ -1,3 +1,7 @@ This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches) Patches applied to this directory: +3180702 - Export block UUID with custom Layout Builder blocks +Source: https://www.drupal.org/files/issues/2024-08-05/3180702-2383-10.3.1.patch + + diff --git a/core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php b/core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php index a1fb950b..c4b66078 100644 --- a/core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php +++ b/core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php @@ -132,7 +132,7 @@ class SetInlineBlockDependency implements EventSubscriberInterface { $layout_entity_storage = $this->entityTypeManager->getStorage($layout_entity_info->layout_entity_type); $layout_entity = $layout_entity_storage->load($layout_entity_info->layout_entity_id); if ($this->isLayoutCompatibleEntity($layout_entity)) { - if ($this->isBlockRevisionUsedInEntity($layout_entity, $block_content)) { + if ($this->isBlockRevisionUsedInEntity($layout_entity, $block_content) || $this->isBlockUuidUsedInEntity($layout_entity, $block_content)) { return $layout_entity; } @@ -157,4 +157,21 @@ class SetInlineBlockDependency implements EventSubscriberInterface { return in_array($block_content->getRevisionId(), $sections_blocks_revision_ids); } + /** + * Determines if a block content uuid is used in an entity. + * + * @param \Drupal\Core\Entity\EntityInterface $layout_entity + * The layout entity. + * @param \Drupal\block_content\BlockContentInterface $block_content + * The block content. + * + * @return bool + * TRUE if the block content uuid is used as an inline block in the + * layout entity. + */ + protected function isBlockUuidUsedInEntity(?EntityInterface $layout_entity, BlockContentInterface $block_content) { + $sections_blocks_revision_ids = $this->getInlineBlockUuidsInSections($this->getEntitySections($layout_entity)); + return in_array($block_content->uuid(), $sections_blocks_revision_ids); + } + } diff --git a/core/modules/layout_builder/src/LayoutEntityHelperTrait.php b/core/modules/layout_builder/src/LayoutEntityHelperTrait.php index 1abf3221..9b72ce8b 100644 --- a/core/modules/layout_builder/src/LayoutEntityHelperTrait.php +++ b/core/modules/layout_builder/src/LayoutEntityHelperTrait.php @@ -57,6 +57,26 @@ trait LayoutEntityHelperTrait { return $revision_ids; } + /** + * Gets uuids for layout sections. + * + * @param \Drupal\layout_builder\Section[] $sections + * The layout sections. + * + * @return string[] + * The uuids. + */ + protected function getInlineBlockUuidsInSections(array $sections) { + $uuids = []; + foreach ($this->getInlineBlockComponents($sections) as $component) { + $configuration = $component->getPlugin()->getConfiguration(); + if (!empty($configuration['block_uuid'])) { + $uuids[] = $configuration['block_uuid']; + } + } + return $uuids; + } + /** * Gets the sections for an entity if any. *