File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,18 @@ public function getElement(): ?ElementInterface
119
119
}
120
120
121
121
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 ();
123
134
}
124
135
125
136
return null ;
You can’t perform that action at this time.
0 commit comments