Skip to content

Commit

Permalink
Merge pull request #16315 from craftcms/bugfix/getting-element-by-uid
Browse files Browse the repository at this point in the history
when getting element by uid check for unpublished draft too
  • Loading branch information
brandonkelly authored Dec 11, 2024
2 parents a8bf002 + 37c6f58 commit 35f7de5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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

0 comments on commit 35f7de5

Please sign in to comment.