I used this two classes in modules/custom/my_ckeditor/src/Plugin/CKEditorPlugin:
<?php
namespace Drupal\my_ckeditor\Plugin\CKEditorPlugin;
use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\ckeditor\Annotation\CKEditorPlugin;
use Drupal\Core\Annotation\Translation;
use Drupal\editor\Entity\Editor;
/**
* Defines the "templates" plugin.
*
* @CKEditorPlugin(
* id = "dialog",
* label = @Translation("CKEditor Dialog"),
* module = "ckeditor"
* )
*/
class Dialog extends PluginBase implements CKEditorPluginInterface
{
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getDependencies().
*/
function getDependencies(Editor $editor)
{
return array();
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getLibraries().
*/
function getLibraries(Editor $editor)
{
return array();
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::isInternal().
*/
function isInternal()
{
return false;
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getFile().
*/
function getFile()
{
$plugin = drupal_get_path('module', 'my_ckeditor') . '/js/plugins/dialog/plugin.js';
return $plugin;
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getConfig().
*/
public function getConfig(Editor $editor)
{
return array();
}
}
<?php
namespace Drupal\my_ckeditor\Plugin\CKEditorPlugin;
use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\ckeditor\CKEditorPluginButtonsInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\ckeditor\Annotation\CKEditorPlugin;
use Drupal\Core\Annotation\Translation;
use Drupal\editor\Entity\Editor;
/**
* Defines the "templates" plugin.
*
* @CKEditorPlugin(
* id = "templates",
* label = @Translation("CKEditor Templates"),
* module = "ckeditor"
* )
*/
class Templates extends PluginBase implements CKEditorPluginInterface, CKEditorPluginButtonsInterface
{
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getDependencies().
*/
function getDependencies(Editor $editor)
{
return array('dialog');
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getLibraries().
*/
function getLibraries(Editor $editor)
{
return array();
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::isInternal().
*/
function isInternal()
{
return false;
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getFile().
*/
function getFile()
{
$plugin = drupal_get_path('module', 'my_ckeditor') . '/js/plugins/templates/plugin.js';
return $plugin;
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getConfig().
*/
public function getConfig(Editor $editor)
{
return array();
}
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getConfig().
*/
public function getButtons()
{
return array(
'Templates' => array(
'label' => t('Templates'),
'image' => drupal_get_path('module', 'my_ckeditor') . '/js/plugins/templates/icons/templates.png',
),
);
}
}
The CKEditor plugins (Dialog & Templates) are placed in modules/custom/my_ckeditor/js/plugins
You also need a custom JS-file for your templates:
(function ($, Drupal, CKEDITOR) {
"use strict";
Drupal.behaviors.myCkeditor = {
attach: function (context, settings) {
var templates_path = '/modules/custom/my_ckeditor/templates/ckeditor/';
var templates = [
{
title: Drupal.t('Title'),
description: Drupal.t('Description'),
image: 'preview.gif',
html: 'My Template'
}
];
// Remove default templates
CKEDITOR.on("instanceLoaded", function () {
CKEDITOR.config.templates_files = [];
});
// Load tempaltes
CKEDITOR.on("instanceReady", function () {
if (CKEDITOR.plugins.get('templates')) {
CKEDITOR.config.templates_replaceContent = false;
CKEDITOR.addTemplates('default', {
imagesPath: templates_path,
templates: templates
});
}
});
}
};
})(jQuery, Drupal, CKEDITOR);
This talk can help you: https://www.youtube.com/watch?feature=player_detailpage&v=h9KV_VRvIG8#t=1965
oembed
plugin, where it shows on the config page, but not on the node edit page, even though the Chrome console shows the Javascript Files were loaded.