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

when getting element by uid check for unpublished draft too #16315

Merged
merged 2 commits into from
Dec 11, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 5

## Unreleased

- Fixed a bug where field conditions weren’t taking effect within Matrix fields set to inline-editable blocks mode, if the owner element didn’t support drafts. ([#16315](https://github.com/craftcms/cms/pull/16315))

## 5.5.6.1 - 2024-12-11

- Fixed a bug where Tags fields had “Replace” actions. ([#16310](https://github.com/craftcms/cms/issues/16310))
Expand Down
21 changes: 15 additions & 6 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2351,19 +2351,28 @@ private function _elementById(
}

if ($elementUid) {
$withDrafts = false;
if (!Craft::$app->getConfig()->getGeneral()->autosaveDrafts) {
$withDrafts = null;
$element = $this->_elementQuery($elementType)
->uid($elementUid)
->siteId($siteId)
->preferSites($preferSites)
->unique()
->status(null)
->one();

if ($element) {
return $element;
}

// check for an unpublished draft if we got this far
// (e.g. newly added matrix "block" or where autosaveDrafts is off)
// https://github.com/craftcms/cms/issues/15985
return $this->_elementQuery($elementType)
->uid($elementUid)
->siteId($siteId)
->preferSites($preferSites)
// when autosaveDrafts is off, we need search among drafts too
// https://github.com/craftcms/cms/issues/15985
->drafts($withDrafts)
->unique()
->status(null)
->draftOf(false)
->one();
}

Expand Down