diff --git a/ORM/Versioning/ChangeSet.php b/ORM/Versioning/ChangeSet.php
index 55cf5255e..ded5ccbcc 100644
--- a/ORM/Versioning/ChangeSet.php
+++ b/ORM/Versioning/ChangeSet.php
@@ -378,9 +378,7 @@ class ChangeSet extends DataObject {
$fields = new FieldList();
$fields->push(TextField::create('Name', $this->fieldLabel('Name')));
if($this->isInDB()) {
- $state = ReadonlyField::create('State', $this->fieldLabel('State'))
- ->setDontEscape(true);
- $fields->push($state); // Escape is done in react
+ $fields->push(ReadonlyField::create('State', $this->fieldLabel('State')));
}
$this->extend('updateCMSFields', $fields);
return $fields;
diff --git a/forms/FormField.php b/forms/FormField.php
index 97756113f..37e43bc35 100644
--- a/forms/FormField.php
+++ b/forms/FormField.php
@@ -256,7 +256,8 @@ class FormField extends RequestHandler {
private static $casting = array(
'FieldHolder' => 'HTMLFragment',
'Field' => 'HTMLFragment',
- 'AttributesHTML' => 'HTMLFragment',
+ 'AttributesHTML' => 'HTMLFragment', // property $AttributesHTML version
+ 'getAttributesHTML' => 'HTMLFragment', // method $getAttributesHTML($arg) version
'Value' => 'Text',
'extraClass' => 'Text',
'ID' => 'Text',
diff --git a/forms/HTMLReadonlyField.php b/forms/HTMLReadonlyField.php
index 34f077caf..b6bae7fc7 100644
--- a/forms/HTMLReadonlyField.php
+++ b/forms/HTMLReadonlyField.php
@@ -7,6 +7,20 @@
*/
class HTMLReadonlyField extends ReadonlyField {
private static $casting = [
- 'Value' => 'HTMLFragment'
+ 'Value' => 'HTMLFragment',
+ 'ValueEntities' => 'HTMLFragment',
];
+
+ public function Field($properties = array()) {
+ return $this->renderWith($this->getTemplates());
+ }
+
+ /**
+ * Return value with all values encoded in html entities
+ *
+ * @return string Raw HTML
+ */
+ public function ValueEntities() {
+ return htmlentities($this->Value(), ENT_COMPAT, 'UTF-8');
+ }
}
diff --git a/forms/ReadonlyField.php b/forms/ReadonlyField.php
index f9987337d..5ccd2055c 100644
--- a/forms/ReadonlyField.php
+++ b/forms/ReadonlyField.php
@@ -29,9 +29,18 @@ class ReadonlyField extends FormField {
* allowed to be modified by the user.
*
* @param boolean $includeHiddenField
+ * @return $this
*/
public function setIncludeHiddenField($includeHiddenField) {
$this->includeHiddenField = $includeHiddenField;
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ public function getIncludeHiddenField() {
+ return $this->includeHiddenField;
}
public function performReadonlyTransformation() {
diff --git a/forms/UploadField.php b/forms/UploadField.php
index b19595973..d0a582a8a 100644
--- a/forms/UploadField.php
+++ b/forms/UploadField.php
@@ -1017,7 +1017,7 @@ class UploadField extends FileField {
$mergedConfig = array_merge($config, $this->ufConfig);
return parent::Field(array(
- 'configString' => str_replace('"', """, Convert::raw2json($mergedConfig)),
+ 'configString' => Convert::raw2json($mergedConfig),
'config' => new ArrayData($mergedConfig),
'multiple' => $allowedMaxFileNumber !== 1
));
diff --git a/forms/htmleditor/HTMLEditorField.php b/forms/htmleditor/HTMLEditorField.php
index 60b904771..8a6eca7bb 100644
--- a/forms/htmleditor/HTMLEditorField.php
+++ b/forms/htmleditor/HTMLEditorField.php
@@ -3,6 +3,7 @@ use Embed\Adapters\AdapterInterface;
use Embed\Embed;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\DataObject;
+use SilverStripe\ORM\FieldType\DBField;
/**
@@ -153,15 +154,9 @@ class HTMLEditorField extends TextareaField {
*/
class HTMLEditorField_Readonly extends HTMLReadonlyField {
private static $casting = [
- 'Value' => 'HTMLText'
+ 'Value' => 'HTMLText',
];
- public function Field($properties = array()) {
- $valforInput = $this->value ? Convert::raw2att($this->value) : "";
- return "id() . "\">"
- . ( $this->value && $this->value != '' ? $this->value : '(not set)' )
- . "name."\" value=\"".$valforInput."\" />";
- }
public function Type() {
return 'htmleditorfield readonly';
}
@@ -245,7 +240,10 @@ class HTMLEditorField_Toolbar extends RequestHandler {
$contentComposite = new CompositeField(
OptionsetField::create(
'LinkType',
- sprintf($numericLabelTmpl, '1', _t('HTMLEditorField.LINKTO', 'Link to')),
+ DBField::create_field(
+ 'HTMLFragment',
+ sprintf($numericLabelTmpl, '1', _t('HTMLEditorField.LINKTO', 'Link to'))
+ ),
array(
'internal' => _t('HTMLEditorField.LINKINTERNAL', 'Page on the site'),
'external' => _t('HTMLEditorField.LINKEXTERNAL', 'Another website'),
diff --git a/templates/UploadField.ss b/templates/UploadField.ss
index 7fb889a8f..d2416bf1f 100644
--- a/templates/UploadField.ss
+++ b/templates/UploadField.ss
@@ -50,10 +50,10 @@
<% if $canUpload %>
<% else %>
-
+
<% end_if %>
<% if $canAttachExisting %>
diff --git a/templates/forms/HTMLReadonlyField.ss b/templates/forms/HTMLReadonlyField.ss
new file mode 100644
index 000000000..971bf6c3e
--- /dev/null
+++ b/templates/forms/HTMLReadonlyField.ss
@@ -0,0 +1,6 @@
+
+ <% if $Value %>$Value<% else %>(not set)<% end_if %>
+
+<% if $IncludeHiddenField %>
+
+<% end_if %>
diff --git a/tests/forms/HTMLEditorFieldTest.php b/tests/forms/HTMLEditorFieldTest.php
index 120483620..9fae3e69b 100644
--- a/tests/forms/HTMLEditorFieldTest.php
+++ b/tests/forms/HTMLEditorFieldTest.php
@@ -2,6 +2,7 @@
use Filesystem as SS_Filesystem;
use SilverStripe\ORM\DataObject;
+use SilverStripe\ORM\FieldType\DBHTMLText;
/**
@@ -181,6 +182,48 @@ EOS
$this->assertEquals('my_local_image.jpg', $file->Name);
$this->assertEquals('jpg', $file->Extension);
}
+
+ public function testReadonlyField() {
+ $editor = new HTMLEditorField('Content');
+ $fileID = $this->idFromFixture('Image', 'example_image');
+ $editor->setValue(sprintf(
+ '[image src="assets/HTMLEditorFieldTest_example.jpg" width="10" height="20" id="%d"]',
+ $fileID
+ ));
+ /** @var HTMLReadonlyField $readonly */
+ $readonly = $editor->performReadonlyTransformation();
+ /** @var DBHTMLText $readonlyContent */
+ $readonlyContent = $readonly->Field();
+
+ $this->assertEquals( <<
+
+
+
+
+EOS
+ ,
+ $readonlyContent->getValue()
+ );
+
+ // Test with include input tag
+ $readonly = $editor->performReadonlyTransformation()
+ ->setIncludeHiddenField(true);
+ /** @var DBHTMLText $readonlyContent */
+ $readonlyContent = $readonly->Field();
+ $this->assertEquals( <<
+
+
+
+
+
+
+EOS
+ ,
+ $readonlyContent->getValue()
+ );
+ }
}
/**
diff --git a/view/ViewableData.php b/view/ViewableData.php
index 10c988583..fdc0b1199 100644
--- a/view/ViewableData.php
+++ b/view/ViewableData.php
@@ -388,9 +388,9 @@ class ViewableData extends Object implements IteratorAggregate {
// Load value from record
if($this->hasMethod($fieldName)) {
$value = call_user_func_array(array($this, $fieldName), $arguments ?: []);
- } else {
- $value = $this->$fieldName;
- }
+ } else {
+ $value = $this->$fieldName;
+ }
// Cast object
if(!is_object($value)) {