Skip to content

Commit 615121d

Browse files
committed
Merge branch 'craft-4' of https://github.com/verbb/workflow into craft-5
2 parents 2698a9a + 6eef1f1 commit 615121d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/models/Review.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,18 @@ public function getElement(): ?ElementInterface
119119
}
120120

121121
if ($this->elementId !== null) {
122-
return $this->_element = Craft::$app->getElements()->getElementById($this->elementId, null, $this->elementSiteId);
122+
// Ensure that we fetch the correct entry based on whether a draft or not. Note that ID will be different for draft or not.
123+
// Using an element query is also easier than `getElementById()` for drafts.
124+
$elementType = Craft::$app->getElements()->getElementTypeById($this->elementId);
125+
$elementQuery = Craft::$app->getElements()->createElementQuery($elementType)->siteId($this->elementSiteId);
126+
127+
if ($this->draftId) {
128+
$elementQuery->draftId($this->draftId)->draftOf($this->elementId);
129+
} else {
130+
$elementQuery->id($this->elementId);
131+
}
132+
133+
return $this->_element = $elementQuery->one();
123134
}
124135

125136
return null;

0 commit comments

Comments
 (0)