Skip to content

Commit

Permalink
Merge pull request #340 from craftcms/feature/331-load-provisional-dr…
Browse files Browse the repository at this point in the history
…afts-when-previewing

Feature/331 load provisional drafts when previewing
  • Loading branch information
brandonkelly authored Feb 18, 2025
2 parents 7a366ba + 1883d34 commit 180145a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for CKEditor for Craft CMS

## Unreleased

- CKEditor fields now show provisional drafts for nested entries when previewing an owner element. ([#340](https://github.com/craftcms/ckeditor/pull/340))

## 4.5.0 - 2025-01-23

- CKEditor now requires Craft CMS 5.6+.
Expand Down
11 changes: 8 additions & 3 deletions src/data/FieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,20 @@ public function loadEntries(): void
$entryIds = $entryChunks->map(fn(Entry $chunk) => $chunk->entryId)->all();

if (!empty($entryIds)) {
$entries = EntryElement::find()
$query = EntryElement::find()
->id($entryIds)
->siteId($this->siteId)
->status(null)
->drafts(null)
->revisions(null)
->trashed(null)
->indexBy('id')
->all();
->indexBy('id');

if (Craft::$app->getRequest()->getIsPreview()) {
$query->withProvisionalDrafts();
}

$entries = $query->all();
} else {
$entries = [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/web/assets/ckeditor/src/entries/entriesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ export default class CraftEntriesUI extends Plugin {
params: {
siteId: siteId,
},
onLoad: () => {
slideout.elementEditor.on('update', () => {
Craft.Preview.refresh();
});
},
onBeforeSubmit: async () => {
// If the nested element is primarily owned by the canonical entry being edited,
// then ensure we're working with a draft and save the nested entry changes to the draft
Expand Down

0 comments on commit 180145a

Please sign in to comment.