diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ba41c1431..6cc9525fb22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - 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)) - 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)) - Fixed a bug where element card labels were getting cut off when wrapped. ([#16325](https://github.com/craftcms/cms/issues/16325)) +- Fixed a PHP error that could occur when eager-loading `owner` or `primaryOwner` on nested elements. ([#16339](https://github.com/craftcms/cms/issues/16339)) ## 5.5.6.1 - 2024-12-11 diff --git a/src/base/NestedElementTrait.php b/src/base/NestedElementTrait.php index f0a7856ca48..58d47b66060 100644 --- a/src/base/NestedElementTrait.php +++ b/src/base/NestedElementTrait.php @@ -38,8 +38,13 @@ public static function eagerLoadingMap(array $sourceElements, string $handle): a case 'owner': case 'primaryOwner': /** @var NestedElementInterface[] $sourceElements */ + $ownerId = $sourceElements[0]->getOwnerId(); + if (!$ownerId) { + return false; + } + return [ - 'elementType' => get_class(reset($sourceElements)), + 'elementType' => Craft::$app->getElements()->getElementTypeById($ownerId), 'map' => array_map(fn(NestedElementInterface $element) => [ 'source' => $element->id, 'target' => match ($handle) {