Ok, i rewrote the function duplicate() in UserDefinedForm.php by myself. It duplicates correctly and takes over the right conditions.
public function duplicate($doWrite = true) {
$page = parent::duplicate($doWrite);
// the form fields
if($this->Fields()) {
foreach($this->Fields() as $field) {
$newField = $field->duplicate();
$newField->ParentID = $page->ID;
$newField->Name = $newField->ClassName.$newField->ID;
//trek eerst de CustomRules uit elkaar
$ar = array();
$ar = unserialize($field->CustomRules);
if(sizeof($ar) >0){
$ConditionField = $ar[0]['ConditionField'];
if($ConditionField != ""){
//$ar2 = preg_split("/(\d+)/", $ConditionField, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
//selecteer sorteervolgorde, classname uit editableformfield waar naam = $ConditionField
$child = DataObject::get('EditableFormField')->where('Name = \''.$ConditionField.'\'')->first();
$sort = $child->Sort;
$classname = $child->ClassName;
//selecteer id, waar sorteervolgorde en nieuwe parent id
$new = DataObject::get('EditableFormField')->where('Sort = '.$sort.' AND ParentID = '.$newField->ParentID)->first();
$ar[0]['ConditionField'] = $new->Name;
$ar = serialize($ar);
$newField->CustomRules = $ar;
}
}
$newField->write();
$newField->doPublish('Stage', 'Live', true);
}
}
$page->doPublish('Stage', 'Live');
// the emails
if($this->EmailRecipients()) {
foreach($this->EmailRecipients() as $email) {
$newEmail = $email->duplicate();
$newEmail->FormID = $page->ID;
$newEmail->write();
}
}
return $page;
}