Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » TinyMCE in ModelAdmin

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

Page: 1
Go to End
Author Topic: 4939 Views
  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    TinyMCE in ModelAdmin Link to this post

    Hi, I'm working in 2.3 rc2 with ModelAdmin, and I'm noticing TinyMCE doesn't seem to work in it. HtmlEditor fields just display as textareas...I'm guessing this is a Javascript issue? Does TinyMCE just not work in ModelAdmin pages or am I doing something wrong here?

  • BLU42 Media
    Avatar
    Community Member
    71 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    I'm just getting to working with ModelAdmin as well ... looks really promising!

    I did some digging into CMSMain and found that the Tiny MCE components are manually added in, so if you just add an HtmlEditorField it's not enough.

    I pulled this code from CMSMain. Try adding this to your init() function in your extended ModelAdmin page:

          // collect languages for TinyMCE spellchecker plugin
          if(Translatable::is_enabled()) {
             $spellcheckLangs = i18n::get_existing_content_languages();
          } else {
             $defaultLang = Translatable::default_lang();
             $spellcheckLangs = array($defaultLang => i18n::get_language_name($defaultLang));
          }
          $spellcheckSpec = array();
          foreach($spellcheckLangs as $lang => $title) $spellcheckSpec[] = "{$title}={$lang}";

          // We don't want this showing up in every ajax-response, it should always be present in a CMS-environment
          if(!Director::is_ajax()) {
             Requirements::javascript(MCE_ROOT . "tiny_mce_src.js");
             Requirements::javascriptTemplate(CMS_DIR . "/javascript/tinymce.template.js", array(
                "ContentCSS" => (SSViewer::current_theme() ? THEMES_DIR . "/" . SSViewer::current_theme() : project()) . "/css/editor.css",
                "BaseURL" => Director::absoluteBaseURL(),
                "Lang" => i18n::get_tinymce_lang(),
                'SpellcheckLangs' => '+' . implode(',', $spellcheckSpec)
             ));
          }

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    Yeah, the crux of the problem is that the tinymce javascript sources are not included at page load time. We have routines trying to include new javascript code "after the fact" dynamically into the existing DOM, but that doesn't seem to work too well with tinymce. I've created a new ticket: http://open.silverstripe.com/ticket/3428

    For now, manually including tinymce_src.js in your ModelAdmin subclass is your best bet.

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    Thanks for the responses, unfortunately just including these makes TinyMCE appear ONCE, but it doesn't save any changes and won't appear after any subsequent AJAX loads. I've been digging through the TinyMCE code and it seems like it breaking because it thinks the editor already exists. No idea why it's not saving, though. Probaby both related to one simple thing that's not happening.

    Anyway I'll keep digging around in it later when I have the time and see if I can find the problem.

  • brice
    Avatar
    Community Member
    51 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    I'm not sure if this has been solved upstream in 2.4 development, but I've gone ahead and added a patch to the [core] ModelAdmin.js that resolves this issue. The patch is available @ the ticket Ingo opened; http://open.silverstripe.com/ticket/3428

    Hope this helps!

    ~ Brice

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    Hi,

    i want to use the TinyMCE Editor together with the data object manager. I have to insert tables with text and images into a database field. I have already had a look at HTMLField, SimpleTinyMCEField or SimpleHTMLEditorField. But with these fields can not manage the task.

    @Brice: Does this patch resolves this problem? I am using 2.3.3 but my ModelAdmin.js differs from yours?!
    @ALL: How can i use TinyMCE together with Uncle Chees Data Object Manager?

    Best regards ~ Carsten

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    Hi brice,

    i have tested your patch and it works fine for me. Thanks a lot.
    Will theses fixes automatically be include in 2.4.0?

    Greetings, Carsten.

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: TinyMCE in ModelAdmin Link to this post

    For the record it seems to not be included in 2.4, but init() function in extended ModelAdmin page should look like:

       function init(){
          parent::init();
          if($this->getRequest()->requestVar("Locale")) {
             $this->Locale = $this->getRequest()->requestVar("Locale");
          } elseif($this->getRequest()->requestVar("locale")) {
             $this->Locale = $this->getRequest()->requestVar("locale");
          } else {
             $this->Locale = Translatable::default_locale();
          }
          Translatable::set_current_locale($this->Locale);
          
          // collect languages for TinyMCE spellchecker plugin.
          // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
          $langName = i18n::get_locale_name($this->Locale);
          HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->Locale}");
                
          Requirements::javascript(CMS_DIR . '/javascript/CMSMain.js');
          Requirements::javascript(CMS_DIR . '/javascript/CMSMain_left.js');
          Requirements::javascript(CMS_DIR . '/javascript/CMSMain_right.js');
       }

    4939 Views
Page: 1
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.