Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Duplication of userforms went wrong at 3.1.0-beta3


Go to End


3 Posts   842 Views

Avatar
quanto

Community Member, 91 Posts

13 May 2013 at 7:14pm

I'm trying to duplicate a page including form. Because 3.0.x doesn't have the ability to duplicate, I choosed to use the 3.1.0 beta
3.

It works brilliant, except a part of the duplication in the form.

When set a CustomRule, and duplicate the page, the new page still get's the Rule from the old source. (e.g. "EditableRadioField13" instead of "EditableRadioField26"). Is there a easy solution without a complete rebuild of the function duplicate()?

Avatar
quanto

Community Member, 91 Posts

17 May 2013 at 1:25am

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;
	}

Avatar
fvue

Community Member, 1 Post

4 June 2013 at 9:54pm