Skip to content

Commit

Permalink
Structure fix part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Sep 19, 2022
1 parent de6d053 commit 7032a00
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/services/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7032a00

Please sign in to comment.