mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #342 from tractorcow/pulls/fix-duplicate
BUG Fix duplication of forms with groups
This commit is contained in:
commit
990535a8e8
@ -170,6 +170,9 @@ class UserFormFieldEditorExtension extends DataExtension {
|
|||||||
* @return DataObject
|
* @return DataObject
|
||||||
*/
|
*/
|
||||||
public function onAfterDuplicate($newPage) {
|
public function onAfterDuplicate($newPage) {
|
||||||
|
// List of EditableFieldGroups, where the
|
||||||
|
// key of the array is the ID of the old end group
|
||||||
|
$fieldGroups = array();
|
||||||
foreach($this->owner->Fields() as $field) {
|
foreach($this->owner->Fields() as $field) {
|
||||||
$newField = $field->duplicate(false);
|
$newField = $field->duplicate(false);
|
||||||
$newField->ParentID = $newPage->ID;
|
$newField->ParentID = $newPage->ID;
|
||||||
@ -177,6 +180,18 @@ class UserFormFieldEditorExtension extends DataExtension {
|
|||||||
$newField->Version = 0;
|
$newField->Version = 0;
|
||||||
$newField->write();
|
$newField->write();
|
||||||
|
|
||||||
|
// If we encounter a group start, record it for later use
|
||||||
|
if($field instanceof EditableFieldGroup) {
|
||||||
|
$fieldGroups[$field->EndID] = $newField;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we encounter an end group, link it back to the group start
|
||||||
|
if($field instanceof EditableFieldGroupEnd && isset($fieldGroups[$field->ID])) {
|
||||||
|
$groupStart = $fieldGroups[$field->ID];
|
||||||
|
$groupStart->EndID = $newField->ID;
|
||||||
|
$groupStart->write();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($field->DisplayRules() as $customRule) {
|
foreach ($field->DisplayRules() as $customRule) {
|
||||||
$newRule = $customRule->duplicate(false);
|
$newRule = $customRule->duplicate(false);
|
||||||
$newRule->ParentID = $newField->ID;
|
$newRule->ParentID = $newField->ID;
|
||||||
|
@ -275,6 +275,29 @@ class UserDefinedFormTest extends FunctionalTest {
|
|||||||
|
|
||||||
// can't compare object since the dates/ids change
|
// can't compare object since the dates/ids change
|
||||||
$this->assertEquals($form->Fields()->First()->Title, $duplicate->Fields()->First()->Title);
|
$this->assertEquals($form->Fields()->First()->Title, $duplicate->Fields()->First()->Title);
|
||||||
|
|
||||||
|
// Test duplicate with group
|
||||||
|
$form2 = $this->objFromFixture('UserDefinedForm', 'page-with-group');
|
||||||
|
$form2Validator = new UserFormValidator();
|
||||||
|
$form2Validator->setForm(new Form(new Controller(), 'Form', new FieldList(), new FieldList()));
|
||||||
|
$this->assertTrue($form2Validator->php($form2->toMap()));
|
||||||
|
|
||||||
|
// Check field groups exist
|
||||||
|
$form2GroupStart = $form2->Fields()->filter('ClassName', 'EditableFieldGroup')->first();
|
||||||
|
$form2GroupEnd = $form2->Fields()->filter('ClassName', 'EditableFieldGroupEnd')->first();
|
||||||
|
$this->assertEquals($form2GroupEnd->ID, $form2GroupStart->EndID);
|
||||||
|
|
||||||
|
// Duplicate this
|
||||||
|
$form3 = $form2->duplicate();
|
||||||
|
$form3Validator = new UserFormValidator();
|
||||||
|
$form3Validator->setForm(new Form(new Controller(), 'Form', new FieldList(), new FieldList()));
|
||||||
|
$this->assertTrue($form3Validator->php($form3->toMap()));
|
||||||
|
|
||||||
|
// Check field groups exist
|
||||||
|
$form3GroupStart = $form3->Fields()->filter('ClassName', 'EditableFieldGroup')->first();
|
||||||
|
$form3GroupEnd = $form3->Fields()->filter('ClassName', 'EditableFieldGroupEnd')->first();
|
||||||
|
$this->assertEquals($form3GroupEnd->ID, $form3GroupStart->EndID);
|
||||||
|
$this->assertNotEquals($form2GroupEnd->ID, $form3GroupStart->EndID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testFormOptions() {
|
function testFormOptions() {
|
||||||
|
@ -13,6 +13,8 @@ EditableFormStep:
|
|||||||
Title: 'Step 2'
|
Title: 'Step 2'
|
||||||
form6step3:
|
form6step3:
|
||||||
Title: 'Step 2'
|
Title: 'Step 2'
|
||||||
|
form7step1:
|
||||||
|
Title: 'Step 1'
|
||||||
|
|
||||||
EditableOption:
|
EditableOption:
|
||||||
option-1:
|
option-1:
|
||||||
@ -96,6 +98,9 @@ EditableTextField:
|
|||||||
field-2:
|
field-2:
|
||||||
Name: Field2
|
Name: Field2
|
||||||
|
|
||||||
|
some-field:
|
||||||
|
Name: SomeField
|
||||||
|
|
||||||
EditableDropdown:
|
EditableDropdown:
|
||||||
basic-dropdown:
|
basic-dropdown:
|
||||||
Name: basic-dropdown
|
Name: basic-dropdown
|
||||||
@ -137,6 +142,15 @@ EditableRadioField:
|
|||||||
Name: radio-option
|
Name: radio-option
|
||||||
Title: Radio Option
|
Title: Radio Option
|
||||||
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
||||||
|
|
||||||
|
EditableFieldGroupEnd:
|
||||||
|
group1end:
|
||||||
|
Name: group1end
|
||||||
|
|
||||||
|
EditableFieldGroup:
|
||||||
|
group1start:
|
||||||
|
Name: group1start
|
||||||
|
End: =>EditableFieldGroupEnd.group1end
|
||||||
|
|
||||||
UserDefinedForm_EmailRecipientCondition:
|
UserDefinedForm_EmailRecipientCondition:
|
||||||
# filtered recipient 1
|
# filtered recipient 1
|
||||||
@ -208,6 +222,11 @@ UserDefinedForm:
|
|||||||
Title: User Defined Form
|
Title: User Defined Form
|
||||||
Fields: =>EditableFormStep.form1step1,=>EditableTextField.basic-text
|
Fields: =>EditableFormStep.form1step1,=>EditableTextField.basic-text
|
||||||
EmailRecipients: =>UserDefinedForm_EmailRecipient.recipient-1, =>UserDefinedForm_EmailRecipient.no-html, =>UserDefinedForm_EmailRecipient.no-data
|
EmailRecipients: =>UserDefinedForm_EmailRecipient.recipient-1, =>UserDefinedForm_EmailRecipient.no-html, =>UserDefinedForm_EmailRecipient.no-data
|
||||||
|
|
||||||
|
page-with-group:
|
||||||
|
Content: 'Page with group'
|
||||||
|
Title: 'page with group'
|
||||||
|
Fields: =>EditableFormStep.form7step1, =>EditableFieldGroup.group1start, =>EditableTextField.some-field, =>EditableFieldGroupEnd.group1end
|
||||||
|
|
||||||
form-with-reset-and-custom-action:
|
form-with-reset-and-custom-action:
|
||||||
Title: Form with Reset Action
|
Title: Form with Reset Action
|
||||||
|
Loading…
Reference in New Issue
Block a user