Implementing CKeditor's plugin
I need to add the Templates plugin into Drupal8 CKeditor. So far it is available on the editor configuration page, but not on a node edit page. The code:
namespace Drupal\module_name\Plugin\CKEditorPlugin;
use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\ckeditor\CKEditorPluginButtonsInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\editor\Entity\Editor;
class ContentTemplates extends PluginBase implements CKEditorPluginInterface, CKEditorPluginButtonsInterface {
public function getButtons() {
return array(
'ContentTemplates' => array(
'label' => t('Content templates'),
'image' => drupal_get_path('module', 'module_name') . '/js/CKeditor/Plugin/templates/icons/templates.png',
'image_rtl' => drupal_get_path('module', 'module_name') . '/js/CKeditor/Plugin/templates/icons/templates-rtl.png',
),
);
}
public function isInternal() {
return FALSE;
}
public function getDependencies(Editor $editor) {
return array('dialog', 'dialogui');
}
public function getLibraries(Editor $editor) {
return array();
}
public function getFile() {
return drupal_get_path('module', 'module_name') . '/js/CKeditor/Plugin/templates/plugin.js';
}
public function getConfig(Editor $editor) {
return array();
}
// TODO: to be sure, should be removed and served by config
function isEnabled(Editor $editor) {
return TRUE;
}
}
I also could see the methods injected by templates/dialogs/templates.js
while inspecting the CKEditor object, but the file is not listed in the Chrome's resources inspector. I also don't see any code changes in this file takes effect (browser and drupal cache disabled, aggregation disabled).
Answers 3
I used this two classes in modules/custom/my_ckeditor/src/Plugin/CKEditorPlugin:
The CKEditor plugins (Dialog & Templates) are placed in modules/custom/my_ckeditor/js/plugins
You also need a custom JS-file for your templates:
This talk can help you: https://www.youtube.com/watch?feature=player_detailpage&v=h9KV_VRvIG8#t=1965
The concept sunk in when I saw this: https://github.com/wwalc/moonocolor
Its the drupal8 implementation for moonocolor plugin of ckeditor
The only additions i could find are the .module file .info.yml file
I did not find any reference to an extra js file. Also in the above solution its not mentioned where the extra js file should be.
My efforts, not working yet https://github.com/baverhey/d8_ckeditor_templates
See the documentation at https://www.drupal.org/developing/api/8/ckeditor.
You can find examples in Drupal 8 core, at:
\Drupal\ckeditor_test\Plugin\CKEditorPlugin\Llama
\Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaButton
\Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextual
\Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextualAndButton