public function copyAsChild($target, $source, $enableInheritance = false, $resetIndex = false)
{
if (method_exists($source, "getElements")) {
$source->getElements();
}
$source->getProperties();
$new = clone $source;
$new->id = null;
$new->setChilds(null);
$new->setKey(Element\Service::getSaveCopyName("document", $new->getKey(), $target));
$new->setParentId($target->getId());
$new->setUserOwner($this->_user->getId());
$new->setUserModification($this->_user->getId());
$new->setDao(null);
$new->setLocked(false);
$new->setCreationDate(time());
if ($resetIndex) {
// this needs to be after $new->setParentId($target->getId()); -> dependency!
$new->setIndex($new->getDao()->getNextIndex());
}
if (method_exists($new, "setPrettyUrl")) {
$new->setPrettyUrl(null);
}
if ($enableInheritance && $new instanceof Document\PageSnippet) {
$new->setElements([]);
$new->setContentMasterDocumentId($source->getId());
}
$new->save();
$this->updateChilds($target, $new);
// triggers actions after the complete document cloning
\Pimcore::getEventManager()->trigger('document.postCopy', $new, ['base_element' => $source]);
return $new;
}