mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUG Fix displayrule versioning
This commit is contained in:
parent
14365c963d
commit
1bf826d34e
@ -410,6 +410,11 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
// Get the field which is effected
|
||||
$formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
|
||||
|
||||
// Skip deleted fields
|
||||
if(!$formFieldWatch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldToWatch = $formFieldWatch->getSelectorField($rule);
|
||||
$fieldToWatchOnLoad = $formFieldWatch->getSelectorField($rule, true);
|
||||
|
||||
|
@ -353,17 +353,20 @@ class EditableFormField extends DataObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this form from a given stage
|
||||
* Delete this field from a given stage
|
||||
*
|
||||
* Wrapper for the {@link Versioned} deleteFromStage function
|
||||
*/
|
||||
public function doDeleteFromStage($stage) {
|
||||
$this->deleteFromStage($stage);
|
||||
|
||||
// Don't forget to delete the related custom rules...
|
||||
foreach ($this->DisplayRules() as $rule) {
|
||||
// Remove custom rules in this stage
|
||||
$rules = Versioned::get_by_stage('EditableCustomRule', $stage)
|
||||
->filter('ParentID', $this->ID);
|
||||
foreach ($rules as $rule) {
|
||||
$rule->deleteFromStage($stage);
|
||||
}
|
||||
|
||||
// Remove record
|
||||
$this->deleteFromStage($stage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,7 +95,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
}
|
||||
}
|
||||
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
parent::doPublish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,13 +106,14 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
* @return void
|
||||
*/
|
||||
public function doDeleteFromStage($stage) {
|
||||
if($this->Options()) {
|
||||
foreach($this->Options() as $option) {
|
||||
// Remove options
|
||||
$options = Versioned::get_by_stage('EditableOption', $stage)
|
||||
->filter('ParentID', $this->ID);
|
||||
foreach($options as $option) {
|
||||
$option->deleteFromStage($stage);
|
||||
}
|
||||
}
|
||||
|
||||
$this->deleteFromStage($stage);
|
||||
parent::doDeleteFromStage($stage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,6 +188,34 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
|
||||
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
|
||||
$this->assertTrue($liveText->Title == $text->Title);
|
||||
|
||||
// Add a display rule to the dropdown
|
||||
$displayRule = new EditableCustomRule();
|
||||
$displayRule->ParentID = $dropdown->ID;
|
||||
$displayRule->ConditionFieldID = $text->ID;
|
||||
$displayRule->write();
|
||||
$ruleID = $displayRule->ID;
|
||||
|
||||
// Not live
|
||||
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
|
||||
$this->assertEmpty($liveRule);
|
||||
|
||||
// Publish form, it's now live
|
||||
$form->doPublish();
|
||||
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
|
||||
$this->assertNotEmpty($liveRule);
|
||||
|
||||
// Remove rule
|
||||
$displayRule->delete();
|
||||
|
||||
// Live rule still exists
|
||||
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
|
||||
$this->assertNotEmpty($liveRule);
|
||||
|
||||
// Publish form, it should remove this rule
|
||||
$form->doPublish();
|
||||
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
|
||||
$this->assertEmpty($liveRule);
|
||||
}
|
||||
|
||||
function testUnpublishing() {
|
||||
|
Loading…
Reference in New Issue
Block a user