Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

HTMLEditorConfig - per Editor configuration - question from a humble n00b.


Go to End
Reply

10 Posts   3007 Views

Avatar
Jimmis

12 January 2011 at 12:15pm Community Member, 4 Posts

Hi there,

Just a quick question, any help would be greatly appreciated.

Is it possible to customize the TinyMCE editor on a per 'TinyMCE Editor Field' basis?

ie: I want 3 TinyMCE fields on a page, each one containing only certain buttons and allowed HTML tags etc.

Thanks in advance.
kind regards
James

Avatar
Willr

12 January 2011 at 8:20pm Forum Moderator, 5511 Posts

You can set the htmleditorconfig values in the getCMSField. You can also have multiple htmleditor configs defined and swap between them when making your getCMSFields.

$fields->addFieldToTab('Root.Main', new HtmlEditorField('Field'));
HtmlEditorConfig::set_active('cms-small');
$fields....
HtmlEditorConfig::set_active('...');

Avatar
muskie9

12 July 2011 at 7:06am Community Member, 10 Posts

Hi all,

Building off of this concept:

Would anything change with setting the config for a front end form?

I have created a new fieldset:

$fields = new FieldSet(
         new TextField('Title', 'Product Name'),
         new CurrencyField('Price', 'Price'),
         new NumericField('TotalAvailable','Total Available'),
         new ImageUploadField('MainImage', 'Main Image'),
         new HTMLEditorField('Content', 'Product Description')
      );

Would I still use something like HtmlEditorConfig::set_active('cms-small') after declaring the new fieldset?

Thanks,

Nic

Avatar
Myrdhin

15 September 2011 at 2:54am (Last edited: 15 September 2011 2:55am), Community Member, 67 Posts

Hello Willr,

I can't make your code works :(

i tried this in my decorator object :

   public function updateCMSFields(FieldSet $fields) {
      // backup current HtmlEditorConfig identifier (is it usefull ?)
      $oldActiveConfig = HtmlEditorConfig::$current;

      $basicConfig = HtmlEditorConfig::get('basic');
      $basicConfig->setButtonsForLine(1, array('bold','italic','underline'));
      $basicConfig->setButtonsForLine(2, array());
      $basicConfig->setButtonsForLine(3, array());
      $basicConfig->setOptions( array(
         'friendly_name' =>'Basic HTML Editor'
      ));

      HtmlEditorConfig::set_active('basic');
      $HtmlEditorField = new HtmlEditorField("Presentation", _t('Presentation.SINGULARNAME', 'Presentation') );
      // restore old current HtmlEditorConfig identifier (is it usefull ?)
      HtmlEditorConfig::set_active($oldActiveConfig);

      $fields->addFieldToTab("Root.Main", $HtmlEditorField);
   }

but all HtmlEditorFields in all Pages (in admin interface) are now 'basic'...

Avatar
Myrdhin

16 September 2011 at 8:23pm Community Member, 67 Posts

I found the [url=https://github.com/silverstripe-labs/silverstripe-recipes/blob/master/forms/CustomConfigHtmlEditorField.php]CustomConfigHtmlEditorField developped by Will in silverstripe-recipes on gitHub[/url]

It works great :D

Thanks Will !

Avatar
mightycoco

21 March 2012 at 6:04am Community Member, 3 Posts

Thanks for the CustomConfigHtmlEditorField tip - that one is really a live-safer :)

Avatar
mats

13 August 2012 at 12:22am Community Member, 5 Posts

Has anybody successfully done different editor configurations in one form with 3.0? Somehow it's always the last active configuration that gets used for all HtmlEditorFields on the page... I aim to have two fields allowing only bold and italic formatting plus one full-fledged editor field in my form. Whatever i do though, i end up with having one config or the other on all three fields. Is there some way to apply a configuration per editor instance?

Any help greatly appreciated,
mats

Avatar
muskie9

13 August 2012 at 2:37am Community Member, 10 Posts

Here's a video tut by uncle cheese utilizing bootstrap forms with SS3. I think he goes through configuring the HTMLEditorFields:

http://www.leftandmain.com/silverstripe-screencasts/2012/07/03/bootstrap-forms-for-silverstripe-3/

Go to Top