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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Customizing SimpleTinyMCE


Go to End


5 Posts   1721 Views

Avatar
Samba Sam

Community Member, 85 Posts

24 February 2010 at 3:11pm

Edited: 27/02/2010 10:00am

Hi,
I'm trying to customize the SimpleTinyMce in my DOM pop_up using the code supplied in Uncle Cheese's thread: http://www.silverstripe.org/dataobjectmanager-module-forum/show/262243?start=0

I am getting an error with the following code regarding SimpleTinyMce:

<?php
class Link extends DataObject
{
	static $db = array (
   	'AltText' => 'Varchar(50)',
   	'TitleText' => 'Varchar(50)',
	'Description' => 'Text',
	'LinkUrl' => 'Varchar(50)'
);

	static $has_one = array (
	'LinksPage' => 'LinksPage',
	'LinkImage' => 'Image'
);


public function getDOMThumbnail()
	{return $this->LinkImage()->CroppedImage(50,50);}

function getCMSFields_forPopup()
{
	return new FieldSet(
	new ImageField('LinkImage'),
	new TextField('AltText'),
	new TextField('TitleText'),
	new TextField('LinkUrl'),
	$myfield = new SimpleTinyMCEField('Description');
	$myfield->setButtons(array(
	'cut,paste,|,undo,code','bold,italic,underline,|,justifyleft,justifyright'));
}
}
?>

I've also tried adding the following to my _config.php file instead:

SimpleTinyMCEField::set_default_buttons(array(
'cut,paste,|,undo,code',
'bold,italic,underline,|,justifyleft,justifyright'
));

And changing the previous code to:

...
function getCMSFields_forPopup()
{
	return new FieldSet(
	new ImageField('LinkImage'),
	new TextField('AltText'),
	new TextField('TitleText'),
	new SimpleTinyMCEField('Description'),
	new TextField('LinkUrl')
);
}

That doesn't work either. Nothing happens. None of the text formatting options are there. Just looks like a plain text form in the pop-up.

Alternatively, I also tried using SimpleWysiwygField. Still nothing.
In the _config.php file I put:

  SimpleWysiwygField::set_default_configuration(array(
    array('cut','copy','paste','|','bold','italic','underline','|','left','center','right'),
    array('ol','ul','|','hyperlink','unlink','image','|','formats')
  ));

In the Link.php file, I put:

new SimpleWysiwygField('Description'));

Any help would be appreciated,
Sam

Avatar
Samba Sam

Community Member, 85 Posts

25 February 2010 at 7:55am

Edited: 25/02/2010 7:57am

It appeared to be an issue with DOM's intelligent constructor. It doesn't recognize html fieldsets such as SimpleTinyMCEField.

It worked using the expanded version in the LinksPage.php

public function getCMSFields()
	{
		$fields = parent::getCMSFields();
		$manager = new DataObjectManager(
                    $this,
                    'Links',
                    'Link',
                    array(
                    'DOMThumbnail' => 'Thumbnail', 
                    'AltText' => 'AltText',
                    'TitleText' => 'TitleText',
                    'Description' => 'Link description',
                    'LinkUrl' => 'Url of link'
                    ),
                    'getCMSFields_forPopup'
                    );
		$fields->addFieldToTab("Root.Content.Links", $manager);
		return $fields;
	}

Sam

Avatar
UncleCheese

Forum Moderator, 4102 Posts

25 February 2010 at 8:15am

That's true. The intelligent constructor will look for "getCMSFields".. The "getCMSFields_forPopup" is somewhat deprecated. You should only use that if you're returning a different fieldset for the DOM popup than ModelAdmin.

Avatar
Samba Sam

Community Member, 85 Posts

27 February 2010 at 10:22am

Edited: 27/02/2010 10:23am

Hi,
I got the intelligent constructor to work using "getCMSFields" instead of "getCMSFields_forPopup" as Uncle Cheese suggested.
However, the DOM thumbnail is no longer showing up in my Links tab in the CMS when I use the intelligent constructor. What do I have to do to get the thumbnail to show again.

Also, I get a bluescreen in Firefox after I insert html tagged text into the dataobject pop-up using the html text format icon. It appears after I insert html text, save and then close the pop up. I then have to refresh the browser for the Links tab list to reappear. Is this an issue with SimpleTinyMCE or SS?

Any ideas on both questions?

Thanks,
Sam

Avatar
UncleCheese

Forum Moderator, 4102 Posts

27 February 2010 at 10:54am

If you're using a custom getter like a thumbnail, you need to either pass the DOM constructor an array of fields/headings, or define $summary_fields on your dataobject. It's not smart enough to look for custom getters.