I made a simple plugin, and know how to use the HtmlEditorConfig to enable it and add a button, but where would be the most appropriate place to save the plugin be so that it is not lost in an upgrade?
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.
OK, maybe I don't know how to use the HtlmlEditorConfig to enable the plugin as well as I thought...
I had it working with the standard
HtmlEditorConfig::get('cms')->enablePlugins('testplugin');
when it was in the tinymce plugins folder, but moving the plugin 1 level outside of the standard plugin folder with: HtmlEditorConfig::get('cms')->enablePlugins('../testplugin/');
made it stop working.
Checking the code for HtmlEditorConfig it notes, "If passed in as a map of plugin-name to path, the plugin will be loaded by tinymce.PluginManager.load() instead of through tinyMCE.init(). Keep in mind that these externals plugins require a dash-prefix in their name."
First, based on the documentation for HtmlEditorConfig they use an underscore, not a dash--which is correct?. 2nd, what do I need to rename exactly--just the folder with my plugin, or just prefix the plugin folder name with tinymce(_/-) when enabling it as in the documentation? Finally, does the fact it is loading the plugin with tinymce.PluginManager.load() instead of tinyMCE.init() require me to change the code of the plugin (and how)?
Using SS 2.4
Thanks!!
Hi theoldlr
Did you have any luck getting your plugin to work. I am trying to add some custom plugins to SS, but I am not having any luck with getting them to load the javascript. Any chance of sharing the code to see what customisations are need for SS?
Thanks
Liam
I have looked in to this some more. I have got some custom plugins to work in their own directories (like modules) in SS 2.3 but the same behavior you describe with them not working in SS2.4 is happening (they only work in the tinymce/plugins directory). If anyone can confirm what we are experiencing here and can maybe identify the exact cause of this problem or a solution that would be very helpful.
Cheers
Ok so I finally worked this out. In SS2.4 the directory of tinymce was changed from SS2.3. So if you are to add a plugin to tinymce in your config file you need to specify the directory of it exactly from the plugins directory. So from what I gather the best practice is to place your plugin in the top level directory like a module. Then in your _config.php file you add the plugin like this.
HtmlEditorConfig::get('cms')->enablePlugins('pluginname', '../../../../plugindirectory');
HtmlEditorConfig::get('cms')->addButtonsToLine(2, 'pluginbuttonname');
Now if you want to use a tinymce plugin that is thirdparty and you haven't created it yourself the plugin will be written as though it is inside the tinymce/plugins directory. So if you want to use it in SS as a toplevel module any references to files in tinymce will need to have their paths changed. Here is an example.
Code from plugins html file (pluginname.htm).
<script language="javascript" type="text/javascript" src="../sapphire/thirdparty/tinymce/tiny_mce_popup.js"></script>
<script language="javascript" type="text/javascript" src="../sapphire/thirdparty/tinymce/utils/mctabs.js"></script>
<script language="javascript" type="text/javascript" src="../sapphire/thirdparty/tinymce/utils/form_utils.js"></script>
In addition to this the url to your plugin inside editor_plugin_src.js also needs to be changed to reference the file path of the plugin. Here is an example of the changes that I had to make.
Code from editor_plugin_src.js
// Load plugin specific language pack
tinymce.PluginManager.requireLangPack('../../../../pluginname');
//Code changes in init
file : url + '../../../../../../plugindir/pluginname.htm',
plugin_url : url + '../../../../../../plugindirname', // Plugin absolute URL
//Code changes in addButton
image : url + '../../../../../../pluginanme/img/pluginimg.gif'
Hopefully this will help people when they are having trouble with tinymce.
Thanks
Liam
Just a quick note...
HtmlEditorConfig::get('cms')->enablePlugins('pluginname', '../../../../plugindirectory');
Should actually be...
HtmlEditorConfig::get('cms')->enablePlugins(array('pluginname', '../../../../plugindirectory/editor_plugin.js'));
sorry but nothing described here is working for me. If the plugin I downloaded would at least work in the original sapphire/thirdparty/plugins folder everything would be fine for me.....
I put the plugin named loaded with tinymce.create("tinymce.plugins.Quotes".... in editor_plugin.js of the plugin in the original thirdparty folder and used
HtmlEditorConfig::get('cms')->enablePlugins('Quotes');
HtmlEditorConfig::get('cms')->addButtonsToLine(2, 'Quotes'); // positions plugin
in _config.php to use it.... but NOTHING happens. Not even errormessages that would lead me to where I can do something....
any hint would be appreciated...
oh and my editor is in english although I set the CMS language to german.... how can I fix this????
LITTLE bit frustrated.......
Greetz
Spanky
Ok, I found out it seems the htmleditor config is not set in /mysite/_config.php but in /cms/_config.php, but entering my plugindetails there doesn't do anything either.... so it might be broke... I'll try another one and put it in the sapphire folder... maybe that'll work.
But that the editor is in english is still confusinga s I set the default language with Translatable::set_default_locale('de_DE'); and TinyMCE config loads with "en" from i18n Class..... I even tried both, using Translatable and additionally i18n::set_default_locale('de_DE'); but it is still in english....
please, anybody????