mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
parent
3b43145954
commit
83c2af72ca
@ -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;
|
||||
|
@ -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',
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
));
|
||||
|
@ -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'),
|
||||
|
@ -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 %>
|
||||
|
6
templates/forms/HTMLReadonlyField.ss
Normal file
6
templates/forms/HTMLReadonlyField.ss
Normal 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 %>
|
@ -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="/assets/HTMLEditorFieldTest/f5c7c2f814/HTMLEditorFieldTest-example.jpg" width="10" height="20" id="{$fileID}"]" />
|
||||
|
||||
|
||||
EOS
|
||||
,
|
||||
$readonlyContent->getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user