From 7032a00199a3a458606ccd5104fa7815fbb0e424 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 19 Sep 2022 15:22:36 -0700 Subject: [PATCH] Structure fix part 2 --- src/services/Elements.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/services/Elements.php b/src/services/Elements.php index f8e6736c888..ba09b0a7949 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -1253,20 +1253,17 @@ public function duplicateElement( } // Should we add the clone to the source element's structure? - if (!$element->structureId && $element->getIsDerivative()) { - $canonical = $element->getCanonical(true); - $element->structureId = $canonical->structureId ?? null; - } if ( $placeInStructure && - $element->structureId && - $element->root && $mainClone->getIsCanonical() && !$mainClone->root && - $mainClone->structureId == $element->structureId + (!$mainClone->structureId || !$element->structureId || $mainClone->structureId == $element->structureId) ) { - $mode = isset($newAttributes['id']) ? Structures::MODE_AUTO : Structures::MODE_INSERT; - Craft::$app->getStructures()->moveAfter($element->structureId, $mainClone, $element, $mode); + $canonical = $element->getCanonical(true); + if ($canonical->structureId && $canonical->root) { + $mode = isset($newAttributes['id']) ? Structures::MODE_AUTO : Structures::MODE_INSERT; + Craft::$app->getStructures()->moveAfter($canonical->structureId, $mainClone, $canonical, $mode); + } } // Map it