Skip to content

Commit

Permalink
Fix error when creating block with cloned/pasted prev sibling
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Dec 5, 2024
1 parent 13325e0 commit 478d8a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- Fixed a bug where condition rules for parent block field values were not being applied for new child blocks
- Fixed an error that occurred when creating new blocks whose previous sibling was a cloned or pasted block

## 5.2.18 - 2024-11-27

Expand Down
14 changes: 14 additions & 0 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ public function duplicateBlocks(
bool $deleteOtherBlocks = true,
bool $force = false,
): void {
$draftsService = Craft::$app->getDrafts();
$elementsService = Craft::$app->getElements();
$value = $source->getFieldValue($field->handle);

Expand Down Expand Up @@ -539,6 +540,16 @@ public function duplicateBlocks(
], [
'sortOrder' => $block->getSortOrder(),
], updateTimestamp: false);

// Clean up after a bug that left cloned blocks in a draft state
if ($block->getIsUnpublishedDraft() && !$target->getIsDraft()) {
$draftsService->removeDraftData($block);
Db::delete(Table::ELEMENTS_OWNERS, [
'elementId' => $block->id,
'ownerId' => $source->id,
]);
}

$newBlock = $block;
} else {
$newBlock = $elementsService->duplicateElement($block, $newAttributes);
Expand Down Expand Up @@ -669,7 +680,10 @@ public function duplicateOwnership(Field $field, ElementInterface $canonical, El
)
->unique()
->status(null)
// Account for a bug that left cloned blocks in a draft state
->drafts(null)
->all();

// Opt out of creating structures for other supported sites - we'll be doing that from here if necessary
$this->_saveNeoStructuresForSites($field, $draft, $blocks, $siteId, false);
}
Expand Down

0 comments on commit 478d8a1

Please sign in to comment.