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

nested element card ownership data #339

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
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 a bug where “Edit entry” buttons were only partially translated. ([#337](https://github.com/craftcms/ckeditor/issues/337))
- Fixed a bug where copying and pasting nested entries wasn’t working on non-primary sites. ([#315](https://github.com/craftcms/ckeditor/issues/315))
- Fixed an error that could occur when editing nested entries on newly-created provisional drafts. ([#339](https://github.com/craftcms/ckeditor/pull/339))

## 4.4.0 - 2024-11-12

Expand Down
9 changes: 8 additions & 1 deletion src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ protected function prepValueForInput($value, ?ElementInterface $element, bool $s
}

$value = $chunks
->map(function(BaseChunk $chunk) use ($static, $entries) {
->map(function(BaseChunk $chunk) use ($static, $entries, $element) {
if ($chunk instanceof Markup) {
return $chunk->rawHtml;
}
Expand All @@ -1110,6 +1110,13 @@ protected function prepValueForInput($value, ?ElementInterface $element, bool $s
$entry = $entries[$chunk->entryId];

try {
// set up-to-date owner on the entry
// e.g. when provisional draft was created for the owner and the page was reloaded
$entry->setOwner($element);
if ($entry->id === $entry->getPrimaryOwnerId()) {
$entry->setPrimaryOwner($element);
}

$cardHtml = $this->getCardHtml($entry);
} catch (InvalidConfigException) {
// this can happen e.g. when the entry type has been deleted
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.

6 changes: 4 additions & 2 deletions src/web/assets/ckeditor/src/entries/entriesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ export default class CraftEntriesUI extends Plugin {
const editor = this.editor;
const elementEditor = this.getElementEditor();

let $element = this._getCardElement(entryId);
const ownerId = $element.data('owner-id');

const slideout = Craft.createElementEditor(this.elementType, null, {
elementId: entryId,
params: {
siteId: siteId,
},
onBeforeSubmit: async () => {
let $element = this._getCardElement(entryId);
// 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
if (
Expand All @@ -268,7 +270,7 @@ export default class CraftEntriesUI extends Plugin {
slideout.elementEditor.settings.saveParams.action =
'elements/save-nested-element-for-derivative';
slideout.elementEditor.settings.saveParams.newOwnerId =
elementEditor.getDraftElementId($element.data('owner-id'));
elementEditor.getDraftElementId(ownerId);
}
}
},
Expand Down
Loading