Jump to:

21307 Posts in 5737 Topics by 2603 members

General Questions

SilverStripe Forums » General Questions » HTMLEditorConfig - per Editor configuration - question from a humble n00b.

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

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 1710 Views
  • mats
    Avatar
    Community Member
    5 Posts

    Re: HTMLEditorConfig - per Editor configuration - question from a humble n00b. Link to this post

    Mmh - Uncle Cheese's BootstrapForm Module rocks, but it did not help me with my problem...

    Instead I have - ahem probably - succeded in adapting CustomConfigHtmlEditorField to my needs:

    CustomHtmlEditorfield::create($DBObject, $Title, $NameOfExistingEditorConfig, $Value)

    This gives you a HtmlEditorfield based on a configuration $NameOfExistingEditorConfig.
    Edit: Above became obsolete, see below.

    To the best of my knowledge, this might be a pretty bad hack: I haven't really figured out Entwine (which seems pretty cool) and the PHP/JavaScript Interactions in the backend yet and I am not a programmer.

    Still, here's my code for CustomHtmlEditorfield. It might not be pretty but - for now - it works for me. Any criticism is very much appreciated. Maybe I just reinvented the wheel, but the advocated solutions did not work for me...

    Edit: Did not work as expected after all - created multiple invisible TinyMCE instances

    New approach:

    class CustomHtmlEditorField extends HtmlEditorField {

    protected $config = 'cms';

    public function __construct($name, $title = null, $value = '') {
          TextareaField::__construct($name, $title, $value);
    }

    public function setConfig($config = 'cms') {
    $this->config = $config;
    return $this;
    }

    function Field($properties = array()) {
    $this->include_customjs();
    return parent::Field($properties);
    }

    protected function include_customjs() {
    $this->addExtraClass('htmleditor');
    $configObj = HtmlEditorConfig::get($this->config);
    $configIdString = '_'.$this->config;
    $this->addExtraClass('editorconfig'.$configIdString);

    Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js');
    Requirements::customScript(
    str_replace('ssTinyMceConfig','ssTinyMceConfig'.$configIdString,$configObj->generateJS()).
    "(function($){
    $.entwine('ss', function($) {
    $('textarea.htmleditor.customhtmleditor.editorconfig$configIdString').entwine({
    redraw: function() {
    var config = ssTinyMceConfig$configIdString, self = this, ed = this.getEditor();
    self.css('visibility', '');
    ed.create(this.attr('id'), config, function() {
    self.css('visibility', 'visible');
    });
    }
    });
    });
    })(jQuery);
    ", 'htmlEditorConfig'.$configIdString);
    }
    }

    Editor configurations are now loaded via

    CustomHtmlEditorField::setConfig('my_editor_configuration_name')

    Well, i guess it's still a pretty crude hack

    1710 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.