Skip to content

Commit

Permalink
Merge pull request #339 from craftcms/bugfix/nested-element-card-owne…
Browse files Browse the repository at this point in the history
…rship-data

nested element card ownership data
  • Loading branch information
brandonkelly authored Jan 23, 2025
2 parents 6557d42 + 3c31cc0 commit 184ef8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 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 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

0 comments on commit 184ef8b

Please sign in to comment.