Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/331 load provisional drafts when previewing #340

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+.
11 changes: 8 additions & 3 deletions src/data/FieldData.php
Original file line number Diff line number Diff line change
@@ -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 = [];
}
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
@@ -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