From a Symfony 5 website, I installed the useful bundle fosckeditor (CKEDITOR version 4).
All works fine, I get the CKEDITOR field on my page. Now I want to create a new simple plugin.
I scrupulously followed this official guide and created a new plugin in the <symfony_root_dir>/public/bundle/fosckeditor/plugins/
named 'timestamp' with some files:
In the plugin.js
, I add this code:
CKEDITOR.plugins.add( 'timestamp', {
icons: 'timestamp',
init: function( editor ) {
alert('hello test ?'); // this alert appears when I load the page containing the CKEDITOR
editor.addCommand('insertTimestamp', {
exec: function (editor) {
var now = new Date();
editor.insertHtml('The current date and time is: <em>' + now.toString() + '</em>');
}
});
editor.ui.addButton('timestamp', {
label: 'Insert Timestamp',
command: 'insertTimestamp',
toolbar: 'insert'
})
}
});
And, in <symfony_root_dir>/public/bundle/fosckeditor/config.js
, I added:
CKEDITOR.editorConfig = function( config ) {
config.extraPlugins = ['timestamp'];
// same result if instead I add the custom plugin via a string : config.extraPlugins = 'timestamp';
};
For this simple example, I copy/paste an icon from another plugin, here is the timestamp icon file:
Finally, I reload my page (reload + clear caches). But the Ckeditor toolbar does not change, the custom plugin appears nowhere.
I tried to add the button in the fos_ckeditor.yaml
file like this:
# ...
fos_ck_editor:
# ...
default_config: main_config
configs:
main_config:
# ...
toolbar:
- {
items:
['timestamp']
}
styles:
# ...
But the button of my custom plugin keeps missing in the CKEditor toolbar. I have no javascript error in the browser console, I don't understand where I made the mistake.