mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
HTMLEditorField undefined $dimensionsField (fixes #7494)
Also use fluent API for form field definition to keep field invocations in one place and thereby reduce these kind of bugs.
This commit is contained in:
parent
5d37d55f35
commit
8717deca82
@ -596,35 +596,26 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
$thumbnailURL = FRAMEWORK_DIR . '/images/default_media.png';
|
$thumbnailURL = FRAMEWORK_DIR . '/images/default_media.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
$previewField = new LiteralField("ImageFull",
|
|
||||||
"<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnailURL}?r=" . rand(1,100000)
|
|
||||||
. "' alt='{$file->Name}' />\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
if($file->Width != null){
|
|
||||||
$dimensionsField = new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
|
||||||
$widthField = new TextField('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), $file->Width),
|
|
||||||
$heightField = new TextField('Height', _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'), $file->Height)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
$filePreview = CompositeField::create(
|
$filePreview = CompositeField::create(
|
||||||
CompositeField::create(
|
CompositeField::create(
|
||||||
$previewField
|
new LiteralField(
|
||||||
|
"ImageFull",
|
||||||
|
"<img id='thumbnailImage' class='thumbnail-preview' "
|
||||||
|
. "src='{$thumbnailURL}?r=" . rand(1,100000) . "' alt='{$file->Name}' />\n"
|
||||||
|
)
|
||||||
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
|
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
|
||||||
CompositeField::create(
|
CompositeField::create(
|
||||||
CompositeField::create(
|
CompositeField::create(
|
||||||
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':', $file->Type),
|
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':', $file->Type),
|
||||||
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
|
$urlField = ReadonlyField::create('ClickableURL', _t('AssetTableField.URL','URL'),
|
||||||
sprintf('<a href="%s" target="_blank" class="file">%s</a>', $url, $url)
|
sprintf('<a href="%s" target="_blank" class="file">%s</a>', $url, $url)
|
||||||
)
|
)->addExtraClass('text-wrap')
|
||||||
)
|
)
|
||||||
)->setName("FilePreviewData")->addExtraClass('cms-file-info-data')
|
)->setName("FilePreviewData")->addExtraClass('cms-file-info-data')
|
||||||
)->setName("FilePreview")->addExtraClass('cms-file-info'),
|
)->setName("FilePreview")->addExtraClass('cms-file-info'),
|
||||||
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
|
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
|
||||||
$alignment = new DropdownField(
|
DropdownField::create(
|
||||||
'CSSClass',
|
'CSSClass',
|
||||||
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
|
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
|
||||||
array(
|
array(
|
||||||
@ -633,19 +624,26 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
|
'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
|
||||||
'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
|
'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
|
||||||
)
|
)
|
||||||
),
|
)->addExtraClass('last')
|
||||||
$dimensionsField
|
);
|
||||||
|
if($file->Width != null){
|
||||||
|
$fields->push(
|
||||||
|
FieldGroup::create(
|
||||||
|
_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
||||||
|
TextField::create(
|
||||||
|
'Width',
|
||||||
|
_t('HtmlEditorField.IMAGEWIDTHPX', 'Width'),
|
||||||
|
$file->Width
|
||||||
|
)->setMaxLength(5),
|
||||||
|
TextField::create(
|
||||||
|
'Height',
|
||||||
|
_t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'),
|
||||||
|
$file->Height
|
||||||
|
)->setMaxLength(5)
|
||||||
|
)->addExtraClass('dimensions last')
|
||||||
);
|
);
|
||||||
$urlField->addExtraClass('text-wrap');
|
|
||||||
$urlField->dontEscape = true;
|
|
||||||
if($dimensionsField){
|
|
||||||
$dimensionsField->addExtraClass('dimensions last');
|
|
||||||
$widthField->setMaxLength(5);
|
|
||||||
$heightField->setMaxLength(5);
|
|
||||||
}else{
|
|
||||||
$alignment->addExtraClass('last');
|
|
||||||
}
|
}
|
||||||
|
$urlField->dontEscape = true;
|
||||||
|
|
||||||
if($file->Type == 'photo') {
|
if($file->Type == 'photo') {
|
||||||
$filePreview->FieldList()->insertBefore(new TextField(
|
$filePreview->FieldList()->insertBefore(new TextField(
|
||||||
@ -670,15 +668,20 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
*/
|
*/
|
||||||
protected function getFieldsForFlash($url, $file) {
|
protected function getFieldsForFlash($url, $file) {
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
$dimensionsField = new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
FieldGroup::create(
|
||||||
$widthField = new TextField('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), $file->Width),
|
_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
||||||
$heightField = new TextField('Height', " x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'),
|
TextField::create(
|
||||||
$file->Height)
|
'Width',
|
||||||
)
|
_t('HtmlEditorField.IMAGEWIDTHPX', 'Width'),
|
||||||
|
$file->Width
|
||||||
|
)->setMaxLength(5),
|
||||||
|
TextField::create(
|
||||||
|
'Height',
|
||||||
|
" x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'),
|
||||||
|
$file->Height
|
||||||
|
)->setMaxLength(5)
|
||||||
|
)->addExtraClass('dimensions')
|
||||||
);
|
);
|
||||||
$dimensionsField->addExtraClass('dimensions');
|
|
||||||
$widthField->setMaxLength(5);
|
|
||||||
$heightField->setMaxLength(5);
|
|
||||||
|
|
||||||
$this->extend('updateFieldsForFlash', $fields, $url, $file);
|
$this->extend('updateFieldsForFlash', $fields, $url, $file);
|
||||||
|
|
||||||
@ -696,23 +699,14 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
$thumbnailURL = $url;
|
$thumbnailURL = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
$previewField = new LiteralField("ImageFull",
|
|
||||||
"<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnailURL}?r=" . rand(1,100000)
|
|
||||||
. "' alt='{$file->Name}' />\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
if($file->Width != null){
|
|
||||||
$dimensionsField = new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
|
||||||
$widthField = new TextField('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), $file->Width),
|
|
||||||
$heightField = new TextField('Height', " x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'),
|
|
||||||
$file->Height)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
$filePreview = CompositeField::create(
|
|
||||||
CompositeField::create(
|
CompositeField::create(
|
||||||
$previewField
|
CompositeField::create(
|
||||||
|
LiteralField::create(
|
||||||
|
"ImageFull",
|
||||||
|
"<img id='thumbnailImage' class='thumbnail-preview' "
|
||||||
|
. "src='{$thumbnailURL}?r=" . rand(1,100000) . "' alt='{$file->Name}' />\n"
|
||||||
|
)
|
||||||
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
|
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
|
||||||
CompositeField::create(
|
CompositeField::create(
|
||||||
CompositeField::create(
|
CompositeField::create(
|
||||||
@ -745,7 +739,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
_t('HtmlEditorField.IMAGETITLETEXTDESC', 'For additional information about the image')),
|
_t('HtmlEditorField.IMAGETITLETEXTDESC', 'For additional information about the image')),
|
||||||
|
|
||||||
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
|
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
|
||||||
$alignment = new DropdownField(
|
DropdownField::create(
|
||||||
'CSSClass',
|
'CSSClass',
|
||||||
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
|
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
|
||||||
array(
|
array(
|
||||||
@ -754,18 +748,25 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
|
'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
|
||||||
'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
|
'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
|
||||||
)
|
)
|
||||||
),
|
)->addExtraClass('last')
|
||||||
$dimensionsField
|
);
|
||||||
|
if($file->Width != null){
|
||||||
|
$fields->push(
|
||||||
|
FieldGroup::create(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
||||||
|
TextField::create(
|
||||||
|
'Width',
|
||||||
|
_t('HtmlEditorField.IMAGEWIDTHPX', 'Width'),
|
||||||
|
$file->Width
|
||||||
|
)->setMaxLength(5),
|
||||||
|
TextField::create(
|
||||||
|
'Height',
|
||||||
|
" x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'),
|
||||||
|
$file->Height
|
||||||
|
)->setMaxLength(5)
|
||||||
|
)->addExtraClass('dimensions last')
|
||||||
);
|
);
|
||||||
$urlField->dontEscape = true;
|
|
||||||
if($dimensionsField){
|
|
||||||
$dimensionsField->addExtraClass('dimensions last');
|
|
||||||
$widthField->setMaxLength(5);
|
|
||||||
$heightField->setMaxLength(5);
|
|
||||||
}else{
|
|
||||||
$alignment->addExtraClass('last');
|
|
||||||
}
|
}
|
||||||
|
$urlField->dontEscape = true;
|
||||||
|
|
||||||
$this->extend('updateFieldsForImage', $fields, $url, $file);
|
$this->extend('updateFieldsForImage', $fields, $url, $file);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user