亚艾元模块精选--Drupal编辑器增强

 作者:亚艾元技术部

我们当前使用的版本是Drupal8.8,从D8开始,自身携带了Ckeditor编辑器。默认就提供了所见即所得编辑功能。默认启用的编辑器里面按钮不够丰富,我们为其做了加强。

1, 开启media、media library模块,启用多媒体上传按钮。

2, 增加对font,color的设置,安装模块colorbutton、ckeditor_font、panelbutton,下载对应的js存放到libraries目录.如果没有下载的话,会报警告信息:

Warning: file_get_contents(/libraries/font/plugin.js): failed to open stream: No such file or directory in _locale_parse_js_file() (line 1133 of core\modules\locale\locale.module).

_locale_parse_js_file('/libraries/font/plugin.js')

调整使用的按钮。

  

3, 字体,支持中文:

添加以下代码到libraries\font的plugin.js文件中:

CKEDITOR.config.font_names = '宋体/SimSun;新宋体/NSimSun;仿宋_GB2312/FangSong_GB2312;楷体_GB2312/KaiTi_GB2312;黑体/SimHei;微软雅黑/Microsoft YaHei;'+
'Arial/Arial, Helvetica, sans-serif;' +

这样增强以后,Ckeditor的功能就比较丰富了。

 

上述的两个常见查找js库的时候,路径写死了,默认不支持子目录的形式,我在本地修改了一下。

public function getLibraryPath() {
    $path = '/zhanhui/libraries/colorbutton';
    if (\Drupal::moduleHandler()->moduleExists('libraries')) {
      $path = libraries_get_path('colorbutton');
    }
 
    return $path;
  }


Drupal版本: