Skip to content

Commit

Permalink
when getting element by uid check for unpublished draft too
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Dec 11, 2024
1 parent a8bf002 commit 375df69
Showing 1 changed file with 15 additions and 6 deletions.
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 375df69

Please sign in to comment.