User tests: Successful: Unsuccessful:
Pull Request for Issue #10996 .
The patch make tinyMCE plugin use JDocument::addScriptOptions
/JDocument::getScriptOptions
that automatically allow to override the editor options before the header rendering.
Another improve.
The patch also allow to have multiple editors on the page with specified options for each.
Check whether editor works as before. There was a lot changes in code, I could miss something.
In any system plugin for event onBeforeRender
, try next code:
public function onBeforeRender()
{
$doc = JFactory::getDocument();
$editorOptions = $doc->getScriptOptions('plg_editor_tinymce');
if(empty($editorOptions['tinyMCE']))
{
return;
}
$editorOptions['tinyMCE']['default']['menubar'] = false;
$doc->addScriptOptions('plg_editor_tinymce', $editorOptions);
}
Expected result:
The menu bar should be disabled.
Use "Custom" module, and add there 2 more editor field:
<field name="test1" type="editor" label="test1"/>
<field name="test2" type="editor" label="test2"/>
Then onBeforeRender event do:
public function onBeforeRender()
{
$doc = JFactory::getDocument();
$editorOptions = $doc->getScriptOptions('plg_editor_tinymce');
if(empty($editorOptions['tinyMCE']))
{
return;
}
// Specify options for 'test1' editor
$editorOptions['tinyMCE']['test1']['menubar'] = false;
$editorOptions['tinyMCE']['test1']['toolbar1'] = 'bold italic underline strikethrough';
// For 'test2' use default options, but disable "menubar"
$editorOptions['tinyMCE']['test2'] = $editorOptions['tinyMCE']['default'];
$editorOptions['tinyMCE']['test2']['menubar'] = false;
$doc->addScriptOptions('plg_editor_tinymce', $editorOptions);
}
Expected result:
bold italic underline
buttonsStatus | New | ⇒ | Pending |
Labels |
Added:
?
|
Category | ⇒ | JavaScript Plugins |
Title |
|
I'll help with some documentation if you give me a hint to where it belongs.
Maybe the key of the array should be named something else than "default". There are now 3 different default settings involved. The plugin default ( = Advanced ), the built in tinyMCE default settings and now in the document. Replace with something like "jmce" ?
default
here in Joomla context, and contain info how the plugin is configured, here are parameters selected by user in the plugin configuration.
And we do not work with default options of the tinyMCE.js script directly, in any way.
jmce
are less obvious name
@Fedik
Well I got a little confused. Not important but I need some explanation.
Is this "default" used for your example field test1 or the tinyMCE defaults? For field2 you explicitely load this "default"
In the custom plugin:
$editorOptions['tinyMCE']['test2'] = $editorOptions['tinyMCE']['default'];
Result in the HTML:
"test1":{"menubar":false,"toolbar1":"bold italic underline strikethrough"}
,"test2":{"suffix":".min","baseURL ....
well, maybe then better I will rename it to global
$editorOptions['tinyMCE']['default']
there all options chosen by user in the plugin configuration. So they used by default for all "tinyMCE" editors in Joomla.
When you do:
$editorOptions['tinyMCE']['default']['menubar'] = false;
You override option chosen by the user in the plugin configuration. And it will affect all "tinyMCE" editors in Joomla, except those you override by next 'test1' example.
When you do:
$editorOptions['tinyMCE']['test1'] = array();
$editorOptions['tinyMCE']['test1']['menubar'] = false;
$editorOptions['tinyMCE']['test1']['toolbar1'] = 'bold italic underline strikethrough';
You fully ignore options chosen by user in the plugin configuration.
When you do:
$editorOptions['tinyMCE']['test2'] = $editorOptions['tinyMCE']['default'];
$editorOptions['tinyMCE']['test2']['menubar'] = false;
You copy options chosen by user to an editor with name test2
, and modify them (['menubar'] = false
) only for this editor instance.
@Fedik
Thanks! That's what I was assuming. God to get confirmed.
A simple test without copied options. (test1)
I changed tinyMCE to use
instead of
. Test1 still uses the tinyMCE fallback (default)
. As expected.
If you want ta add a button like charmap, you have to add a "plugin-string" with "charmap" as well. As expected.
Category | JavaScript Plugins | ⇒ | Layout JavaScript External Library Plugins Front End |
I have tested this item
I will check
I have tested this item
@schnuti can you mark your test in the issue tracker: https://issues.joomla.org/tracker/joomla-cms/11157
So we can move this to RTC?
I have tested this item
All is well since my last test. New test, same result.
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
Currently we need to ask @brianteeman or anyone from the PLT to do this
We should also add the new feature label maybe
Labels |
Added:
?
|
@Fedik , @dgt41 and anyone else with ideas around those overrides. If you have some time, please read the question I added on the Google dev. list
Testing override of TinyMCE settings
@Fedik
I'm trying some more overrides and have found a problem. I want to load plugins from external source ( = not the tinymce plugin path). I want to use this for some available plugins.
This works when I add it directly to a tinymce init but not when I add it in the override.
...],
external_plugins: { 'cbtinybuttons' : 'http://localhost/j3/media/com_mycom/js/cbtinybuttons.min.js'},
toolbar: ' ...
I've tried a lot with single and double quotes but tinymce breaks and no editor is loaded.
$external_plugins = '{ "cbtinybuttons" : "'.JUri::root(true).
'/media/com_mycom/js/cbtinybuttons.min.js"}';
$editorOptions['tinyMCE']['default']['external_plugins'] = $external_plugins;
Result in the HTML source:
..."}],"external_plugins":"{ \"cbtinybuttons\" : \"\/j3\/media\/com_oejcb\/js\/cbtinybuttons.min.js\"}","toolbar2...`
I see a difference that there are : included in the parameter.
Any idea?
@Fedik
Thanks a lot!
This works as well! I loaded two tinymce plugins from another path in the media folder.
Maybe my code above would also work but this is obviously the way to do it.
If someone else want to test it ->
I used the wrong JUri! It has to be without true i.e. JUri::root() and without the first slash / . Write then the rest as Fedik says.
Now I'll make another test. Not really a test, I will use it.
As I do not have any plugins that modifies any of three textarea fields, I use TinyMce for inline editing of those fields in frontend.
I'll move that code to use this tinyMce override instead of the other special coding.
I'm only trying to prove, how useful it can be.
I have tested this item
- Tested int article edit in different modes and it works
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-10-01 09:12:46 |
Closed_By | ⇒ | rdeutz |
Labels |
Removed:
?
|
I have tested this item✅ successfully on 7b4b16c
I used a fresh 3.6 instance.
1. Tested article edit and custom module with all three tinyMCE settings (Simple, Advanced and Extended, backend and frontend) All OK!
2. Activated a plugin that overrides the settings and tested again as 1. Override OK!
3. Changed the plugin to use three different settings as described. Tested with "extra fields" added as parameters to the Custom Module. I got one "normal" editor and two modified. -> OK!
I'll have some use of 3. as well.?
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11157.