我有一个可以工作的扩展插件(myplugin),它扩展了drupalimagecaption插件,扩展了drupalimage,扩展了原始图片插件。现在我想给myplugin插件添加一个额外的工具栏按钮。下面是我尝试添加的方法:
(function (CKEDITOR) {
'use strict';
CKEDITOR.plugins.add('myplugin', {
icons: 'drupalimage,DoubleImage',
requires: 'drupalimagecaption',
hidpi: true,
beforeInit: function (editor) {
// [...] Here are some overwrites
var imageSaveCallback = function (data) {
editor.fire('saveSnapshot');
var content = data.image_render;
editor.insertHtml(content);
editor.fire('saveSnapshot');
};
// Implementation before initializing plugin.
editor.addCommand('InsertDoubleImage', {
canUndo: true,
exec: function (editor, data) {
Drupal.ckeditor.openDialog(editor,
Drupal.url('mydrupalmodule/dialog/double_image/' + editor.config.drupal.format),
{},
imageSaveCallback,
{}
);
}
});
// Register the toolbar button.
if (editor.ui.addButton) {
editor.ui.addButton('DoubleImage', {
label: Drupal.t('Upload Double Image'),
command: 'InsertDoubleImage'
});
}
}
});
})(CKEDITOR);我的主要问题是,为什么这个按钮没有出现在drupal的管理UI中,所以我不能添加到CKeditor的工具栏中。我还有一个PHP类,它加载这个文件(这个脚本所在的位置),我还在那里定义了new和current按钮:
public function getButtons() {
return [
'DrupalImage' => array(
'label' => t('Single Image Popup'),
'image' => drupal_get_path('module', 'mydrupalmodule') . '/js/plugins/elevation/icons/drupalimage.png',
),
'DoubleImage' => array(
'label' => t('Double Image Popup'),
'image' => drupal_get_path('module', 'mydrupalmodule') . '/js/plugins/elevation/icons/DoubleImage.png',
),
];
}实际上我不知道我错过了什么,我也找不到为什么不想工作……(仅覆盖有效,但按钮不显示...)如果你覆盖了一个现有的插件就不能添加新的按钮?
发布于 2017-12-08 22:04:06
好了,我找到问题了。如果我想在Drupal8中为CKeditor创建一个插件,我需要扩展CKEditorPluginBase,而不是PluginBase类。它们在DrupalImageCaption类(我将其用作基类)中扩展了PluginBase,但这在我的示例中不起作用。
https://stackoverflow.com/questions/47714194
复制相似问题