Skip to content

Commit

Permalink
Fixed nested element creation
Browse files Browse the repository at this point in the history
ownerId was no longer getting set via setAttributesFromRequest(), after #15898
  • Loading branch information
brandonkelly committed Oct 20, 2024
1 parent 24d8532 commit f74f9d5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit f74f9d5

Please sign in to comment.