diff --git a/forms/FormField.php b/forms/FormField.php index 0d0ebe525..787569cb1 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -157,6 +157,14 @@ class FormField extends RequestHandler { */ protected $attributes = array(); + /** + * @config + * @var array + */ + private static $casting = array( + 'Value' => 'Text', + ); + /** * Takes a field name and converts camelcase to spaced words. Also resolves combined field * names with dot syntax to spaced words. diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index 246603e83..11faa5ac1 100644 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -26,6 +26,14 @@ class HtmlEditorField extends TextareaField { */ private static $sanitise_server_side = false; + /** + * @config + * @var array + */ + private static $casting = array( + 'Value' => 'HTMLText', + ); + protected $rows = 30; /** diff --git a/forms/ReadonlyField.php b/forms/ReadonlyField.php index a2bd5888b..87aa37e63 100644 --- a/forms/ReadonlyField.php +++ b/forms/ReadonlyField.php @@ -49,10 +49,24 @@ class ReadonlyField extends FormField { } public function Value() { - if($this->value) return $this->dontEscape ? $this->value : Convert::raw2xml($this->value); + if($this->value) return $this->value; else return '(' . _t('FormField.NONE', 'none') . ')'; } + /** + * This is a legacy fix to ensure that the `dontEscape` flag has an impact on readonly fields + * now that we've moved to casting template values more rigidly + * + * @param string $field + * @return string + */ + public function castingHelper($field) { + if ($field == 'Value' && $this->dontEscape) { + return 'HTMLText'; + } + return parent::castingHelper($field); + } + public function getAttributes() { return array_merge( parent::getAttributes(), diff --git a/forms/TextareaField.php b/forms/TextareaField.php index f907d21fc..d40edee8c 100644 --- a/forms/TextareaField.php +++ b/forms/TextareaField.php @@ -85,11 +85,4 @@ class TextareaField extends FormField { return $parent; } - - /** - * @return string - */ - public function Value() { - return htmlentities($this->value, ENT_COMPAT, 'UTF-8'); - } } diff --git a/tests/forms/TextareaFieldTest.php b/tests/forms/TextareaFieldTest.php index 1847754fc..103fa269e 100644 --- a/tests/forms/TextareaFieldTest.php +++ b/tests/forms/TextareaFieldTest.php @@ -2,16 +2,6 @@ class TextareaFieldTest extends SapphireTest { - /** - * Quick smoke test to ensure that text is being encoded properly. - */ - public function testTextEncoding() { - $inputText = "These are some unicodes: äöü"; - $field = new TextareaField("Test", "Test"); - $field->setValue($inputText); - $this->assertContains('These are some unicodes: äöü', $field->Field()); - } - /** * Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields. */