ENHANCEMENT Added 'updateImageForm', 'updateFlashForm', 'updateLinkForm' hooks to HtmlEditorField (the imageform hook was necessary to make the 'pixlr' module work) (see #3938) (from r100753)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105642 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-05-25 04:56:02 +00:00
parent c8ac8a274d
commit c81a788ba7
2 changed files with 80 additions and 43 deletions

View File

@ -269,6 +269,8 @@ class HtmlEditorField_Toolbar extends RequestHandler {
$form->unsetValidator();
$form->loadDataFrom($this);
$this->extend('updateLinkForm', $form);
return $form;
}
@ -279,51 +281,58 @@ class HtmlEditorField_Toolbar extends RequestHandler {
* @return Form
*/
function ImageForm() {
$form = new Form(
$this->controller,
"{$this->name}/ImageForm",
new FieldSet(
new LiteralField(
'Heading',
sprintf('<h3>%s</h3>', _t('HtmlEditorField.IMAGE', 'Image'))
),
$contentComposite = new CompositeField(
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)
)
)
$fields = new FieldSet(
new LiteralField(
'Heading',
sprintf('<h3>%s</h3>', _t('HtmlEditorField.IMAGE', 'Image'))
),
new FieldSet(
new FormAction('insertimage', _t('HtmlEditorField.BUTTONINSERTIMAGE', 'Insert image'))
$contentComposite = new CompositeField(
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",
$fields,
$actions
);
$contentComposite->addExtraClass('content');
// Allow other people to extend the fields being added to the imageform
$this->extend('updateImageForm', $form);
$form->unsetValidator();
$form->disableSecurityToken();
$form->loadDataFrom($this);
@ -353,14 +362,15 @@ class HtmlEditorField_Toolbar extends RequestHandler {
new FieldSet(
new FormAction("insertflash", _t('HtmlEditorField.BUTTONINSERTFLASH', 'Insert Flash'))
)
);
);
$contentComposite->addExtraClass('content');
$form->unsetValidator();
$this->extend('updateFlashForm', $form);
$form->unsetValidator();
$form->loadDataFrom($this);
$form->disableSecurityToken();
return $form;
}
}

View File

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