diff --git a/src/Forms/HTMLEditor/HTMLEditorField.php b/src/Forms/HTMLEditor/HTMLEditorField.php index 9075a5895..63ef950c2 100644 --- a/src/Forms/HTMLEditor/HTMLEditorField.php +++ b/src/Forms/HTMLEditor/HTMLEditorField.php @@ -190,4 +190,14 @@ class HTMLEditorField extends TextareaField $stateDefaults['data'] = $config->getConfigSchemaData(); return $stateDefaults; } + + /** + * Return value with all values encoded in html entities + * + * @return string Raw HTML + */ + public function ValueEntities() + { + return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8', false); + } } diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php index 8fadaa8c6..68ff44b51 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php @@ -208,4 +208,25 @@ EOS $readonlyContent->getValue() ); } + + public function testValueEntities() + { + $inputText = "The company & partners"; + $field = new HTMLEditorField("Content"); + $field->setValue($inputText); + + $this->assertEquals( + "The company & partners", + $field->obj('ValueEntities')->forTemplate() + ); + + $inputText = "The company && partners"; + $field = new HTMLEditorField("Content"); + $field->setValue($inputText); + + $this->assertEquals( + "The company && partners", + $field->obj('ValueEntities')->forTemplate() + ); + } }