From 6e69972c35047f1c2ff23b126d3951f161aefb84 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Thu, 8 Jun 2017 21:01:55 +1000 Subject: [PATCH 1/2] fix default values for EditableMultipleOptionField subclasses --- .../editableformfields/EditableCheckboxGroupField.php | 2 +- code/model/editableformfields/EditableDropdown.php | 2 +- code/model/editableformfields/EditableOption.php | 7 ++++++- code/model/editableformfields/EditableRadioField.php | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/code/model/editableformfields/EditableCheckboxGroupField.php b/code/model/editableformfields/EditableCheckboxGroupField.php index f98faf3..b80554a 100755 --- a/code/model/editableformfields/EditableCheckboxGroupField.php +++ b/code/model/editableformfields/EditableCheckboxGroupField.php @@ -22,7 +22,7 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField // Set the default checked items $defaultCheckedItems = $this->getDefaultOptions(); if ($defaultCheckedItems->count()) { - $field->setDefaultItems($defaultCheckedItems->map('EscapedTitle')->keys()); + $field->setDefaultItems($defaultCheckedItems->map('EscapedValue')->keys()); } $this->doUpdateFormField($field); diff --git a/code/model/editableformfields/EditableDropdown.php b/code/model/editableformfields/EditableDropdown.php index a576c1a..d175f23 100755 --- a/code/model/editableformfields/EditableDropdown.php +++ b/code/model/editableformfields/EditableDropdown.php @@ -38,7 +38,7 @@ class EditableDropdown extends EditableMultipleOptionField // Set default $defaultOption = $this->getDefaultOptions()->first(); if ($defaultOption) { - $field->setValue($defaultOption->EscapedTitle); + $field->setValue($defaultOption->EscapedValue); } $this->doUpdateFormField($field); return $field; diff --git a/code/model/editableformfields/EditableOption.php b/code/model/editableformfields/EditableOption.php index 5062ec2..040a29b 100644 --- a/code/model/editableformfields/EditableOption.php +++ b/code/model/editableformfields/EditableOption.php @@ -80,7 +80,12 @@ class EditableOption extends DataObject return Convert::raw2att($this->Title); } - /** + public function getEscapedValue() + { + return Convert::raw2att($this->Value); + } + + /** * @param Member $member * @return bool */ diff --git a/code/model/editableformfields/EditableRadioField.php b/code/model/editableformfields/EditableRadioField.php index 745c757..e4fd4ac 100755 --- a/code/model/editableformfields/EditableRadioField.php +++ b/code/model/editableformfields/EditableRadioField.php @@ -34,7 +34,7 @@ class EditableRadioField extends EditableMultipleOptionField // Set default item $defaultOption = $this->getDefaultOptions()->first(); if ($defaultOption) { - $field->setValue($defaultOption->EscapedTitle); + $field->setValue($defaultOption->EscapedValue); } $this->doUpdateFormField($field); return $field; From 4b2669242deb117da72475a446614992f4e36d60 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Tue, 13 Jun 2017 09:49:02 +1000 Subject: [PATCH 2/2] leave escaping of value to template --- .../editableformfields/EditableCheckboxGroupField.php | 2 +- code/model/editableformfields/EditableDropdown.php | 2 +- code/model/editableformfields/EditableOption.php | 9 ++++----- code/model/editableformfields/EditableRadioField.php | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/code/model/editableformfields/EditableCheckboxGroupField.php b/code/model/editableformfields/EditableCheckboxGroupField.php index b80554a..8bcdaa1 100755 --- a/code/model/editableformfields/EditableCheckboxGroupField.php +++ b/code/model/editableformfields/EditableCheckboxGroupField.php @@ -22,7 +22,7 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField // Set the default checked items $defaultCheckedItems = $this->getDefaultOptions(); if ($defaultCheckedItems->count()) { - $field->setDefaultItems($defaultCheckedItems->map('EscapedValue')->keys()); + $field->setDefaultItems($defaultCheckedItems->map('Value')->keys()); } $this->doUpdateFormField($field); diff --git a/code/model/editableformfields/EditableDropdown.php b/code/model/editableformfields/EditableDropdown.php index d175f23..b3a8b8e 100755 --- a/code/model/editableformfields/EditableDropdown.php +++ b/code/model/editableformfields/EditableDropdown.php @@ -38,7 +38,7 @@ class EditableDropdown extends EditableMultipleOptionField // Set default $defaultOption = $this->getDefaultOptions()->first(); if ($defaultOption) { - $field->setValue($defaultOption->EscapedValue); + $field->setValue($defaultOption->Value); } $this->doUpdateFormField($field); return $field; diff --git a/code/model/editableformfields/EditableOption.php b/code/model/editableformfields/EditableOption.php index 040a29b..74e6a82 100644 --- a/code/model/editableformfields/EditableOption.php +++ b/code/model/editableformfields/EditableOption.php @@ -75,16 +75,15 @@ class EditableOption extends DataObject return $this->canEdit($member); } + /** + * @deprecated 5.0 Use "$Title.XML" in templates instead + * @return string + */ public function getEscapedTitle() { return Convert::raw2att($this->Title); } - public function getEscapedValue() - { - return Convert::raw2att($this->Value); - } - /** * @param Member $member * @return bool diff --git a/code/model/editableformfields/EditableRadioField.php b/code/model/editableformfields/EditableRadioField.php index e4fd4ac..e51295c 100755 --- a/code/model/editableformfields/EditableRadioField.php +++ b/code/model/editableformfields/EditableRadioField.php @@ -34,7 +34,7 @@ class EditableRadioField extends EditableMultipleOptionField // Set default item $defaultOption = $this->getDefaultOptions()->first(); if ($defaultOption) { - $field->setValue($defaultOption->EscapedValue); + $field->setValue($defaultOption->Value); } $this->doUpdateFormField($field); return $field;