mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added 'updateImageForm', 'updateFlashForm', 'updateLinkForm' hooks to HtmlEditorField (the imageform hook was necessary to make the 'pixlr' module work) (see #3938)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@100753 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2b69344d39
commit
9e7611e891
@ -261,6 +261,8 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
||||
|
||||
$form->loadDataFrom($this);
|
||||
|
||||
$this->extend('updateLinkForm', $form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@ -271,46 +273,53 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
||||
* @return Form
|
||||
*/
|
||||
function ImageForm() {
|
||||
$fields = new FieldSet(
|
||||
new LiteralField('Heading', '<h2><img src="cms/images/closeicon.gif" alt="' . _t('HtmlEditorField.CLOSE', 'close') . '" title="' . _t('HtmlEditorField.CLOSE', 'close') . '" />' . _t('HtmlEditorField.IMAGE', 'Image') . '</h2>'),
|
||||
new TreeDropdownField('FolderID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'),
|
||||
new CompositeField(new FieldSet(
|
||||
new LiteralField('ShowUpload', '<p class="showUploadField"><a href="#">'. _t('HtmlEditorField.SHOWUPLOADFORM', 'Upload File') .'</a></p>'),
|
||||
new FileField("Files[0]" , _t('AssetAdmin.CHOOSEFILE','Choose file: ')),
|
||||
new LiteralField('Response', '<div id="UploadFormResponse"></div>'),
|
||||
new HiddenField('UploadMode', 'Upload Mode', 'CMSEditor') // used as a hook for doUpload switching
|
||||
)),
|
||||
new TextField('getimagesSearch', _t('HtmlEditorField.SEARCHFILENAME', 'Search by file name')),
|
||||
new ThumbnailStripField('FolderImages', 'FolderID', 'getimages'),
|
||||
new TextField('AltText', _t('HtmlEditorField.IMAGEALTTEXT', 'Alternative text (alt) - shown if image cannot be displayed'), '', 80),
|
||||
new TextField('ImageTitle', _t('HtmlEditorField.IMAGETITLE', 'Title text (tooltip) - for additional information about the image')),
|
||||
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
|
||||
new DropdownField(
|
||||
'CSSClass',
|
||||
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
|
||||
array(
|
||||
'left' => _t('HtmlEditorField.CSSCLASSLEFT', 'On the left, with text wrapping around.'),
|
||||
'leftAlone' => _t('HtmlEditorField.CSSCLASSLEFTALONE', 'On the left, on its own.'),
|
||||
'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
|
||||
'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
|
||||
)
|
||||
),
|
||||
new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
||||
new TextField('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), 100),
|
||||
new TextField('Height', " x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'), 100)
|
||||
)
|
||||
);
|
||||
|
||||
$actions = new FieldSet(
|
||||
new FormAction('insertimage', _t('HtmlEditorField.BUTTONINSERTIMAGE', 'Insert image'))
|
||||
);
|
||||
|
||||
$form = new Form(
|
||||
$this->controller,
|
||||
"{$this->name}/ImageForm",
|
||||
new FieldSet(
|
||||
new LiteralField('Heading', '<h2><img src="cms/images/closeicon.gif" alt="' . _t('HtmlEditorField.CLOSE', 'close') . '" title="' . _t('HtmlEditorField.CLOSE', 'close') . '" />' . _t('HtmlEditorField.IMAGE', 'Image') . '</h2>'),
|
||||
new TreeDropdownField('FolderID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'),
|
||||
new CompositeField(new FieldSet(
|
||||
new LiteralField('ShowUpload', '<p class="showUploadField"><a href="#">'. _t('HtmlEditorField.SHOWUPLOADFORM', 'Upload File') .'</a></p>'),
|
||||
new FileField("Files[0]" , _t('AssetAdmin.CHOOSEFILE','Choose file: ')),
|
||||
new LiteralField('Response', '<div id="UploadFormResponse"></div>'),
|
||||
new HiddenField('UploadMode', 'Upload Mode', 'CMSEditor') // used as a hook for doUpload switching
|
||||
)),
|
||||
new TextField('getimagesSearch', _t('HtmlEditorField.SEARCHFILENAME', 'Search by file name')),
|
||||
new ThumbnailStripField('FolderImages', 'FolderID', 'getimages'),
|
||||
new TextField('AltText', _t('HtmlEditorField.IMAGEALTTEXT', 'Alternative text (alt) - shown if image cannot be displayed'), '', 80),
|
||||
new TextField('ImageTitle', _t('HtmlEditorField.IMAGETITLE', 'Title text (tooltip) - for additional information about the image')),
|
||||
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
|
||||
new DropdownField(
|
||||
'CSSClass',
|
||||
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
|
||||
array(
|
||||
'left' => _t('HtmlEditorField.CSSCLASSLEFT', 'On the left, with text wrapping around.'),
|
||||
'leftAlone' => _t('HtmlEditorField.CSSCLASSLEFTALONE', 'On the left, on its own.'),
|
||||
'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
|
||||
'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
|
||||
)
|
||||
),
|
||||
new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
|
||||
new TextField('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), 100),
|
||||
new TextField('Height', " x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'), 100)
|
||||
)
|
||||
),
|
||||
new FieldSet(
|
||||
new FormAction('insertimage', _t('HtmlEditorField.BUTTONINSERTIMAGE', 'Insert image'))
|
||||
)
|
||||
$fields,
|
||||
$actions
|
||||
);
|
||||
|
||||
$form->disableSecurityToken();
|
||||
$form->loadDataFrom($this);
|
||||
|
||||
// Allow other people to extend the fields being added to the imageform
|
||||
$this->extend('updateImageForm', $form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@ -333,9 +342,12 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
||||
)
|
||||
);
|
||||
|
||||
$form->disableSecurityToken();
|
||||
$form->disableSecurityToken();
|
||||
$form->loadDataFrom($this);
|
||||
$form->disableSecurityToken();
|
||||
|
||||
$this->extend('updateFlashForm', $form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ class HtmlEditorFieldTest extends FunctionalTest {
|
||||
|
||||
public static $use_draft_site = true;
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
'HtmlEditorField_Toolbar' => array('HtmlEditorFieldTest_DummyImageFormFieldExtension')
|
||||
);
|
||||
|
||||
public function testBasicSaving() {
|
||||
$sitetree = new SiteTree();
|
||||
$editor = new HtmlEditorField('Content');
|
||||
@ -169,5 +173,28 @@ class HtmlEditorFieldTest extends FunctionalTest {
|
||||
$element = new SimpleXMLElement(html_entity_decode((string) new SimpleXMLElement($editor->Field())));
|
||||
$this->assertNotContains('ss-broken', (string) $element['class']);
|
||||
}
|
||||
|
||||
|
||||
public function testExtendImageFormFields() {
|
||||
$controller = new ContentController();
|
||||
|
||||
$toolbar = new HtmlEditorField_Toolbar($controller, 'DummyToolbar');
|
||||
|
||||
$imageForm = $toolbar->ImageForm();
|
||||
$this->assertTrue(HtmlEditorFieldTest_DummyImageFormFieldExtension::$update_called);
|
||||
$this->assertEquals($imageForm->Fields(), HtmlEditorFieldTest_DummyImageFormFieldExtension::$fields);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class HtmlEditorFieldTest_DummyImageFormFieldExtension extends Extension implements TestOnly {
|
||||
public static $fields = null;
|
||||
public static $update_called = false;
|
||||
|
||||
public function updateImageForm($form) {
|
||||
self::$update_called = true;
|
||||
self::$fields = $form->Fields();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user