Skip to content

Commit

Permalink
Only show unsaved drafts within Matrix fields, not derivative drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 30, 2025
1 parent f23854f commit dc5c782
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed an error that occurred when accessing the `edit/<elementId>` route for a draft that no longer existed.
- Fixed a bug where Matrix fields set to inline-editable blocks view were showing drafts of nested entries.

## 5.6.3 - 2024-01-29

Expand Down
12 changes: 11 additions & 1 deletion src/elements/NestedElementManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ private function getValue(ElementInterface $owner, bool $fetchAll = false): Elem
->drafts(null)
->savedDraftsOnly()
->status(null)
->limit(null);
->limit(null)
->andWhere([
'or',
['elements.draftId' => null],
['elements.canonicalId' => null],
]);
}

return $query;
Expand Down Expand Up @@ -893,6 +898,11 @@ private function deleteOtherNestedElements(ElementInterface $owner, array $excep
->status(null)
->siteId($owner->siteId)
->andWhere(['not', ['elements.id' => $except]])
->andWhere([
'or',
['elements.draftId' => null],
['elements.canonicalId' => null],
])
->all();

$elementsService = Craft::$app->getElements();
Expand Down
11 changes: 10 additions & 1 deletion src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,16 @@ private function blockInputHtml(EntryQuery|ElementCollection|null $value, ?Eleme
}

if ($value instanceof EntryQuery) {
$value = $value->getCachedResult() ?? $value->drafts(null)->status(null)->limit(null)->all();
$value = $value->getCachedResult() ?? (clone $value)
->drafts(null)
->status(null)
->limit(null)
->andWhere([
'or',
['elements.draftId' => null],
['elements.canonicalId' => null],
])
->all();
}

$view = Craft::$app->getView();
Expand Down

0 comments on commit dc5c782

Please sign in to comment.