SilverStripe 4 TinyMCE Customisation Tips

From a great post on the Slack channel (I forget who wrote it, sorry) I was able to pick up that you could globally turn off the Paste as Plaintext pop up.

Put this in app/config.php (which is pretty empty these days) and it changes every TinyMCE on the CMS.

// Sort out the TinyMCE Globally
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
call_user_func(function () {
	$config = TinyMCEConfig::get('cms');
	$config->setOption('paste_plaintext_inform', false);
});

I then assumed that because that worked I could do the same for individual DataObjects and Custom Pages.

Add the class namespace at the top of your DataObject / Page class:
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;

then in getCMSFields() add:

  // Customise the TinyMCE
  $config = TinyMCEConfig::get('cms');
  $config->setOption('paste_plaintext_inform', false); // repeat of above
  $config->removeButtons('formatselect', 'outdent', 'indent', 'table', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'paste');
// this also works but 'table' is removed above
$config->disablePlugins('table');

What I’d like to establish is a complete list of the standard SS4 set of TinyMCE button names that we can remove or disable / enable at will. Obviously you can also do this depending on who logged into the Admin CMS so advanced users can have all the buttons but if your users are always pasting in MS Word text (mine do all the time) you can leave only the paste as text option for them (you can but they’ll still paste rubbish in, of course). They definitely don’t need tables / image insert, etc.

It would also be amazing if we could put the buttons that are on line 2 on line 1 of the TinyMCE.

I will update this post as people contribute. I’ve made a good start but I couldn’t quite get everything as I wanted. Thank you :slight_smile:

1 Like

Hi Gelert, to put all the buttons on one line, I simply add something like this to my _config.php file:

TinyMCEConfig::get('cms')->setButtonsForLine(1, 'formatselect', 'bold', 'bullist', 'sslink', 'unlink','ssmedia', 'ssembed', 'code');
TinyMCEConfig::get('cms')->setButtonsForLine(2, ''); // no button
TinyMCEConfig::get('cms')->setButtonsForLine(3, ''); // no button

I hope it can help,
Stan

2 Likes

Thank you, that is an elegant solution.

A post was split to a new topic: TinyMCE plugins