Skip to content

Commit

Permalink
Fixed #16251
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
brandonkelly committed Dec 1, 2024
1 parent 23b3e3e commit cf41c5f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fixed an error that could occur when saving an element with an invalid Link field value. ([#16212](https://github.com/craftcms/cms/issues/16212))
- Fixed a bug where sortable checkbox selects were displaying menu buttons even when only one option was selected. ([#16213](https://github.com/craftcms/cms/issues/16213))
- Fixed a bug where it wasn’t possible to sort embedded element indexes by custom fields.
- Fixed a bug where changes to nested elements weren’t getting saved to a draft of the parent, if the element editor was triggered via the “Edit” action menu item. ([#16251](https://github.com/craftcms/cms/issues/16251))

## 5.5.3 - 2024-11-22

Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

101 changes: 56 additions & 45 deletions src/web/assets/cp/src/js/NestedElementManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,54 +412,25 @@ Craft.NestedElementManager = Garnish.Base.extend(

initElement($element) {
if (Garnish.hasAttr($element, 'data-editable')) {
// Double-clicks
this.addListener($element, 'dblclick,taphold', (ev) => {
if ($(ev.target).closest('a[href],button,[role=button]').length) {
// Let the link/button do its thing
return;
if (!$(ev.target).closest('a[href],button,[role=button]').length) {
this.createElementEditor($element);
}

const slideout = Craft.createElementEditor(
this.elementType,
$element,
{
onBeforeSubmit: async () => {
// If the nested element is primarily owned by the same owner element it was queried for,
// then ensure we're working with a draft and save the nested entry changes to the draft
// note: this workflow doesn't apply to entries nested directly in global sets as globals don't use element editor
if (
typeof this.elementEditor !== 'undefined' &&
Garnish.hasAttr($element, 'data-owner-is-canonical') &&
!this.elementEditor.settings.isUnpublishedDraft
) {
await slideout.elementEditor.checkForm(true, true);
await this.markAsDirty();
if (
this.elementEditor.settings.draftId &&
slideout.elementEditor.settings.draftId
) {
if (!slideout.elementEditor.settings.saveParams) {
slideout.elementEditor.settings.saveParams = {};
}
slideout.elementEditor.settings.saveParams.action =
'elements/save-nested-element-for-derivative';
slideout.elementEditor.settings.saveParams.newOwnerId =
this.settings.ownerId;
}
}
},
onSubmit: (ev) => {
if (ev.data.id != $element.data('id')) {
// swap the element with the new one
$element
.attr('data-id', ev.data.id)
.data('id', ev.data.id)
.data('owner-id', ev.data.ownerId);
Craft.refreshElementInstances(ev.data.id);
}
},
}
);
});

// "Edit" action menu item
const $editBtn = $element
.find('.action-btn')
.data('disclosureMenu')
?.$container.find('[data-edit-action]');
if ($editBtn.length) {
// Override the default event listener
$editBtn.off('activate');
this.addListener($editBtn, 'activate', () => {
this.createElementEditor($element);
});
}
}

if (this.settings.sortable) {
Expand Down Expand Up @@ -491,6 +462,46 @@ Craft.NestedElementManager = Garnish.Base.extend(
}
},

createElementEditor($element) {
const slideout = Craft.createElementEditor(this.elementType, $element, {
onBeforeSubmit: async () => {
// If the nested element is primarily owned by the same owner element it was queried for,
// then ensure we're working with a draft and save the nested entry changes to the draft
// note: this workflow doesn't apply to entries nested directly in global sets as globals don't use element editor
if (
typeof this.elementEditor !== 'undefined' &&
Garnish.hasAttr($element, 'data-owner-is-canonical') &&
!this.elementEditor.settings.isUnpublishedDraft
) {
await slideout.elementEditor.checkForm(true, true);
await this.markAsDirty();
if (
this.elementEditor.settings.draftId &&
slideout.elementEditor.settings.draftId
) {
if (!slideout.elementEditor.settings.saveParams) {
slideout.elementEditor.settings.saveParams = {};
}
slideout.elementEditor.settings.saveParams.action =
'elements/save-nested-element-for-derivative';
slideout.elementEditor.settings.saveParams.newOwnerId =
this.settings.ownerId;
}
}
},
onSubmit: (ev) => {
if (ev.data.id != $element.data('id')) {
// swap the element with the new one
$element
.attr('data-id', ev.data.id)
.data('id', ev.data.id)
.data('owner-id', ev.data.ownerId);
Craft.refreshElementInstances(ev.data.id);
}
},
});
},

async deleteElement($element) {
const data = Object.assign(await this.getBaseActionData(), {
elementId: $element.data('id'),
Expand Down

0 comments on commit cf41c5f

Please sign in to comment.