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 f98faf3ab..b80554ae5 100755 --- a/code/model/editableformfields/EditableCheckboxGroupField.php +++ b/code/model/editableformfields/EditableCheckboxGroupField.php @@ -22,7 +22,7 @@ public function getFormField() // 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 a576c1a1b..d175f23f4 100755 --- a/code/model/editableformfields/EditableDropdown.php +++ b/code/model/editableformfields/EditableDropdown.php @@ -38,7 +38,7 @@ public function getFormField() // 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 5062ec25c..040a29b53 100644 --- a/code/model/editableformfields/EditableOption.php +++ b/code/model/editableformfields/EditableOption.php @@ -80,7 +80,12 @@ 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 745c75793..e4fd4ac86 100755 --- a/code/model/editableformfields/EditableRadioField.php +++ b/code/model/editableformfields/EditableRadioField.php @@ -34,7 +34,7 @@ public function getFormField() // 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 b80554ae5..8bcdaa183 100755 --- a/code/model/editableformfields/EditableCheckboxGroupField.php +++ b/code/model/editableformfields/EditableCheckboxGroupField.php @@ -22,7 +22,7 @@ public function getFormField() // 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 d175f23f4..b3a8b8eb7 100755 --- a/code/model/editableformfields/EditableDropdown.php +++ b/code/model/editableformfields/EditableDropdown.php @@ -38,7 +38,7 @@ public function getFormField() // 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 040a29b53..74e6a8203 100644 --- a/code/model/editableformfields/EditableOption.php +++ b/code/model/editableformfields/EditableOption.php @@ -75,16 +75,15 @@ public function canDelete($member = null) 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 e4fd4ac86..e51295c73 100755 --- a/code/model/editableformfields/EditableRadioField.php +++ b/code/model/editableformfields/EditableRadioField.php @@ -34,7 +34,7 @@ public function getFormField() // Set default item $defaultOption = $this->getDefaultOptions()->first(); if ($defaultOption) { - $field->setValue($defaultOption->EscapedValue); + $field->setValue($defaultOption->Value); } $this->doUpdateFormField($field); return $field;