Testing override of TinyMCE settings

27 views
Skip to first unread message

Ove Eriksson

unread,
Aug 26, 2016, 7:17:06 AM8/26/16
to Joomla! General Development
There is a PR on GitHub that, if committed (today status RTC, milestone 3.7.0) that allows you to override TinyMCE settings. The basic idea is that you, as an extension developer, can override the settings. e.g. for a special field, where you would prefer a tooolbar similar to the markdown on GitHub or here in the Google list, you can achive that.
1. Force the use of TinyMCE, possible today.
2 Create a system plugin to manipulate the toolbar and remove the menubar.


I'm now testing if and how it would be possible for you, as a site developer, to override in a general way. e.g. different toolbars on frontend/backend and/or for usergroups (if you find reasons not to use 3.d party extensions). This is much harder, since you have to take care of buttons special for some extensions. e.g. the article component adds extended and custom buttons.

I've found a solution. As it looks a bit "crazy" I ask for ideas how to do it efficiantly and stable.

I have to find the "extended" buttons from the original toolbar string.

The string with the buttons (... = more buttons):

"bold
 italic underline strikethrough | ... | styleselect | ...  | code |
button-0Module | button-1Article | button-2Image | button-3PageBreak |
button-4ReadMore"



button-... are the Joomla-extended buttons but there can be more  and probably with other names.

I create a long array with all known buttons

$toolbarRemove   = array('undo', 'redo', ...
                         
'numlist', 'outdent', 'indent', ...
                         
...,
                         
...,
                         
'hr', 'inserttime', ...
                         
'print'
                         
);


Remove those from the string:

$toolbarOrg = str_replace($toolbarRemove, '', $toolbarOrg);


Split on first alpha character to get rid of any '|' and ','. + put it together

   $regexp = '/([a-zA-Z0-9])/';
   $toolbarRest
= preg_split($regexp, $toolbarOrg, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

   $toolbarXtd
= count($toolbarRest) == 3 ? ' | '.$toolbarRest[1] . $toolbarRest[2]: '';
 
   $toolbar
= $mytoolbar.toolbarXtd;


Great if someone has a better idea. The regex thing?
Reply all
Reply to author
Forward
0 new messages