From c80c0475379a0dbdb93735391ada8d70a667b0cf Mon Sep 17 00:00:00 2001 From: i-just Date: Wed, 11 Dec 2024 11:03:23 +0000 Subject: [PATCH] if owner just got a provisional draft, set data-owner-id to its id --- src/Field.php | 9 ++++++++- src/web/assets/ckeditor/src/entries/entriesui.js | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Field.php b/src/Field.php index 35618d3..9058b2c 100644 --- a/src/Field.php +++ b/src/Field.php @@ -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; } @@ -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 diff --git a/src/web/assets/ckeditor/src/entries/entriesui.js b/src/web/assets/ckeditor/src/entries/entriesui.js index 8222368..083cf5a 100644 --- a/src/web/assets/ckeditor/src/entries/entriesui.js +++ b/src/web/assets/ckeditor/src/entries/entriesui.js @@ -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 ( @@ -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); } } },