Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » Duplication of userforms went wrong at 3.1.0-beta3

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

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

Page: 1
Go to End
Author Topic: 321 Views
  • quanto
    Avatar
    Community Member
    81 Posts

    Duplication of userforms went wrong at 3.1.0-beta3 Link to this post

    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()?

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: Duplication of userforms went wrong at 3.1.0-beta3 Link to this post

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

  • fvue
    Avatar
    Community Member
    1 Post
    321 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.