Skip to content

Commit 952361d

Browse files
committed
Fixed #16339
1 parent 1b0bf2f commit 952361d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- 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))
1010
- Fixed a bug where Matrix fields’ entry types weren’t maintaining their original block type order when upgrading to Craft 5. ([#16314](https://github.com/craftcms/cms/issues/16314))
1111
- Fixed a bug where element card labels were getting cut off when wrapped. ([#16325](https://github.com/craftcms/cms/issues/16325))
12+
- Fixed a PHP error that could occur when eager-loading `owner` or `primaryOwner` on nested elements. ([#16339](https://github.com/craftcms/cms/issues/16339))
1213

1314
## 5.5.6.1 - 2024-12-11
1415

src/base/NestedElementTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ public static function eagerLoadingMap(array $sourceElements, string $handle): a
3838
case 'owner':
3939
case 'primaryOwner':
4040
/** @var NestedElementInterface[] $sourceElements */
41+
$ownerId = $sourceElements[0]->getOwnerId();
42+
if (!$ownerId) {
43+
return false;
44+
}
45+
4146
return [
42-
'elementType' => get_class(reset($sourceElements)),
47+
'elementType' => Craft::$app->getElements()->getElementTypeById($ownerId),
4348
'map' => array_map(fn(NestedElementInterface $element) => [
4449
'source' => $element->id,
4550
'target' => match ($handle) {

0 commit comments

Comments
 (0)