How to add a plugin to CKeditor with a package ?

Permalink 2 users found helpful
5.7 use a nice way to add plugin to redactor but what about CKEditor ? HOw to updgrade my package ?

sebastienj
View Replies: View Best Answer
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Hello,

First, you put your plugin somewhere in your package. Personally, I put it in js/plugins/pluginHandle.

Then you add a file register.js inside the folder just next to the plugin.js file

In that file you add:

if (typeof CKEDITOR !== 'undefined') {
    CKEDITOR.plugins.addExternal('pluginHandle', CCM_REL + '/packages/package_folder/js/plugins/pluginHandle/');
}


Then, in your package's controller, you need to activate the plugin.
You need those libraries:
use Concrete\Core\Editor\Plugin;
use Concrete\Core\Asset\AssetList as AssetList;
use \Concrete\Core\Support\Facade\Application as Application;

Then put this code in the on_start() function:
$app = Application::getFacadeApplication();
$editor = $app->make('editor');
$pluginManager = $editor->getPluginManager();
$al = AssetList::getInstance();
$al->register('javascript', 'editor/ckeditor4/pluginHandle',  'js/plugins/pluginHandle/register.js', array(), 'package_handle');
$al->registerGroup('editor/ckeditor4/pluginHandle', array( array('javascript', 'editor/ckeditor4/pluginHandle')));
$plugin = new Plugin();
$plugin->setKey('pluginHandle');
$plugin->setName('Plugin Name');
$plugin->requireAsset('editor/ckeditor4/pluginHandle');
if (!$pluginManager->isAvailable($plugin)) {
    $pluginManager->register($plugin);
}
if (!$pluginManager->isSelected($plugin)) {
    $key = $plugin->getKey();

Make sure you replace all instances of 'PluginHandle' with your actual plugin handle and 'Plugin Name' with the plugin name and 'package_handle' with the package handle.
It should work.
sebastienj replied on at Permalink Reply
sebastienj
Wow ! Thanks for this quick and complete reply. I will try it !