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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

TinyMCE in ModelAdmin

Go to End

8 Posts   5680 Views

Nathan Cox

Community Member, 99 Posts

22 January 2009 at 4:51pm

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

Community Member, 71 Posts

23 January 2009 at 9:50am

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)


Forum Moderator, 801 Posts

25 January 2009 at 8:41pm

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:

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

Nathan Cox

Community Member, 99 Posts

27 January 2009 at 11:29am

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.


Community Member, 52 Posts

17 October 2009 at 8:31am

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;

Hope this helps!

~ Brice


Community Member, 173 Posts

20 October 2009 at 3:01am

Edited: 20/10/2009 3:02am


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


Community Member, 173 Posts

22 October 2009 at 1:04am

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.


Community Member, 56 Posts

12 May 2010 at 8:55pm

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

	function 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();
		// collect languages for TinyMCE spellchecker plugin.
		// see
		$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');