BUG Fix some regressions from #5653 (#5806)

This commit is contained in:
Damian Mooyman 2016-07-14 14:43:53 +12:00 committed by Sam Minnée
parent 3b43145954
commit 83c2af72ca
10 changed files with 88 additions and 19 deletions

View File

@ -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;

View File

@ -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',

View File

@ -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');
}
}

View File

@ -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() {

View File

@ -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
));

View File

@ -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 "<span class=\"readonly typography\" id=\"" . $this->id() . "\">"
. ( $this->value && $this->value != '<p></p>' ? $this->value : '<i>(not set)</i>' )
. "</span><input type=\"hidden\" name=\"".$this->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'),

View File

@ -50,10 +50,10 @@
<% if $canUpload %>
<label class="ss-uploadfield-fromcomputer ss-ui-button ui-corner-all" title="<%t UploadField.FROMCOMPUTERINFO 'Upload from your computer' %>" data-icon="drive-upload">
<%t UploadField.FROMCOMPUTER 'From your computer' %>
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="file"<% if $multiple %> multiple="multiple"<% end_if %> />
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString.ATT" type="file"<% if $multiple %> multiple="multiple"<% end_if %> />
</label>
<% else %>
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="hidden" />
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString.ATT" type="hidden" />
<% end_if %>
<% if $canAttachExisting %>

View File

@ -0,0 +1,6 @@
<span class="readonly typography" id="$ID">
<% if $Value %>$Value<% else %><i>(not set)</i><% end_if %>
</span>
<% if $IncludeHiddenField %>
<input type="hidden" name="$Name.ATT" value="$ValueEntities.RAW" />
<% end_if %>

View File

@ -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
<span class="readonly typography" id="Content">
<img src="/assets/HTMLEditorFieldTest/f5c7c2f814/HTMLEditorFieldTest-example__ResizedImageWyIxMCIsIjIwIl0.jpg" alt="HTMLEditorFieldTest example" width="10" height="20">
</span>
EOS
,
$readonlyContent->getValue()
);
// Test with include input tag
$readonly = $editor->performReadonlyTransformation()
->setIncludeHiddenField(true);
/** @var DBHTMLText $readonlyContent */
$readonlyContent = $readonly->Field();
$this->assertEquals( <<<EOS
<span class="readonly typography" id="Content">
<img src="/assets/HTMLEditorFieldTest/f5c7c2f814/HTMLEditorFieldTest-example__ResizedImageWyIxMCIsIjIwIl0.jpg" alt="HTMLEditorFieldTest example" width="10" height="20">
</span>
<input type="hidden" name="Content" value="[image src=&quot;/assets/HTMLEditorFieldTest/f5c7c2f814/HTMLEditorFieldTest-example.jpg&quot; width=&quot;10&quot; height=&quot;20&quot; id=&quot;{$fileID}&quot;]" />
EOS
,
$readonlyContent->getValue()
);
}
}
/**

View File

@ -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)) {