From c352a434a3b311fe0c4ad2a193a1e1a8806b3e2a Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Sat, 11 Jun 2022 21:14:28 +0200 Subject: [PATCH] Make sure sort order is updated when block ownership is duplicated --- src/services/Service.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/services/Service.php b/src/services/Service.php index c302826..6c546d8 100644 --- a/src/services/Service.php +++ b/src/services/Service.php @@ -869,14 +869,14 @@ public function duplicateBlocks(SuperTableField $field, ElementInterface $source } else { $newBlockId = $block->getCanonicalId(); } + } elseif ($block->primaryOwnerId === $target->id) { + // Only the block ownership was duplicated, so just update its sort order for the target element + Db::update('{{%supertableblocks_owners}}', [ + 'sortOrder' => $block->sortOrder, + ], ['blockId' => $block->id, 'ownerId' => $target->id], updateTimestamp: false); + $newBlockId = $block->id; } else { - // If the block’s primary owner is equal to the target element ID, no need to do anything - if ($block->primaryOwnerId !== $target->id) { - /** @var SuperTableBlockElement $newBlock */ - $newBlockId = $elementsService->duplicateElement($block, $newAttributes)->id; - } else { - $newBlockId = $block->id; - } + $newBlockId = $elementsService->duplicateElement($block, $newAttributes)->id; } $newBlockIds[] = $newBlockId;