Skip to content

Commit 8268106

Browse files
committed
[5.x] Append entry to structure tree directly when duplicating entry with root as parent
1 parent c2ed1ce commit 8268106

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎src/Actions/DuplicateEntry.php‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ private function duplicateEntry(Entry $original, ?string $origin = null)
102102
});
103103

104104
if ($originalParent && $originalParent !== $original->id()) {
105-
$entry->structure()
106-
->in($original->locale())
107-
->appendTo($originalParent->id(), $entry)
108-
->save();
105+
if ($entry->structure()->expectsRoot() && $entry->structure()->in($entry->locale())->root()['entry'] === $originalParent->id()) {
106+
$entry->structure()
107+
->in($original->locale())
108+
->append($entry)
109+
->save();
110+
} else {
111+
$entry->structure()
112+
->in($original->locale())
113+
->appendTo($originalParent->id(), $entry)
114+
->save();
115+
}
109116
}
110117

111118
return $entry;
@@ -127,10 +134,6 @@ protected function getEntryParentFromStructure(Entry $entry)
127134
return null;
128135
}
129136

130-
if ($entry->structure()->expectsRoot() && $entry->structure()->in($entry->locale())->root()['entry'] === $parentEntry->id()) {
131-
return null;
132-
}
133-
134137
return $parentEntry;
135138
}
136139

0 commit comments

Comments
 (0)