From f74f9d5d4a9b354b34bbc88f9110c502182e45e4 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Sun, 20 Oct 2024 07:16:55 -0700 Subject: [PATCH] Fixed nested element creation ownerId was no longer getting set via setAttributesFromRequest(), after #15898 --- src/controllers/ElementsController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index 013571f19b4..f8716331394 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -2239,9 +2239,12 @@ private function _createElement(): ElementInterface /** @var ElementInterface $element */ $element = $this->element = Craft::createObject($this->_elementType); - if ($this->_siteId && $element::isLocalized()) { + if (isset($this->_siteId) && $element::isLocalized()) { $element->siteId = $this->_siteId; } + if (isset($this->_ownerId) && $element instanceof NestedElementInterface) { + $element->setOwnerId($this->_ownerId); + } $element->setAttributesFromRequest($this->_attributes); if (!Craft::$app->getElements()->canSave($element)) {