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

Bugfix/nested elements and revisions #15930

Merged
merged 6 commits into from
Oct 21, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- Fixed a bug `craft\services\Entries::saveSection()` and `craft\services\Volumes::saveVolume()` weren’t respecting predefined UUID values on new models.
- Fixed a bug where Addresses fields in element index view weren’t showing newly-created addresses. ([#15911](https://github.com/craftcms/cms/pull/15911))
- Fixed a bug where disabled Money fields were showing the clear button.
- Fixed a bug where element slideouts had a “Save” button when viewing a revision. ([#15930](https://github.com/craftcms/cms/pull/15930))
- Fixed a bug where element edit pages had a “Revert content from this revision” button for elements that didn’t support revisions. ([#15930](https://github.com/craftcms/cms/pull/15930))
- Fixed an error that occurred when loading a soft-deleted nested entry from a revision. ([#15930](https://github.com/craftcms/cms/pull/15930))

## 5.4.8 - 2024-10-15

Expand Down
14 changes: 10 additions & 4 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
'visibleLayoutElements' => $form ? $form->getVisibleElements() : [],
'updatedTimestamp' => $element->dateUpdated?->getTimestamp(),
'canonicalUpdatedTimestamp' => $canonical->dateUpdated?->getTimestamp(),
'isStatic' => $isRevision,
]
)
);
Expand Down Expand Up @@ -898,7 +899,7 @@ private function _additionalButtons(
}

// Revert content from this revision
if ($isRevision && $canSaveCanonical) {
if ($isRevision && $canSaveCanonical && $element->hasRevisions()) {
$components[] = Html::beginForm() .
Html::actionInput('elements/revert') .
Html::redirectInput('{cpEditUrl}') .
Expand Down Expand Up @@ -2110,15 +2111,20 @@ private function _element(

// Loading an existing element?
if ($this->_draftId || $this->_revisionId) {
$element = $this->_elementQuery($elementType)
$query = $this->_elementQuery($elementType)
->draftId($this->_draftId)
->revisionId($this->_revisionId)
->provisionalDrafts($this->_provisional)
->siteId($siteId)
->preferSites($preferSites)
->unique()
->status(null)
->one();
->status(null);

if ($this->_revisionId) {
$query->trashed(null);
}

$element = $query->one();

if (!$element) {
// check for the canonical element as a fallback
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.

9 changes: 9 additions & 0 deletions src/web/assets/cp/src/js/ElementEditorSlideout.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Craft.ElementEditorSlideout = Craft.CpScreenSlideout.extend(
this.$container.data('elementEditorSettings')
)
);

// if it's supposed to be static, e.g. it's a revision,
// don't show the save button and change wording on the cancel one
if (this.elementEditor.settings.isStatic) {
this.$saveBtn.remove();
this.$cancelBtn[0].innerText = Craft.t('app', 'Close');
}

this.elementEditor.on('beforeSubmit', () => {
Object.keys(this.settings.saveParams).forEach((name) => {
$('<input/>', {
Expand Down Expand Up @@ -187,6 +195,7 @@ Craft.ElementEditorSlideout = Craft.CpScreenSlideout.extend(
onSaveElement: null,
validators: [],
expandData: [],
isStatic: false,
},
}
);