Skip to content

Commit

Permalink
if owner just got a provisional draft, set data-owner-id to its id
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Dec 11, 2024
1 parent edfac1a commit c80c047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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
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 c80c047

Please sign in to comment.