You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Drupal 9中为CKEditor 5添加特殊字符遇插件找不到错误

Drupal 9 中 CKEditor 5 相关问题解决方案

一、添加特殊字符的实现方式

Drupal 9 有专用钩子来扩展 CKEditor 5,无需直接照搬纯前端官方文档,具体操作如下:

  • 启用官方特殊字符插件:通过 hook_ckeditor5_plugin_info_alter() 钩子修改配置,启用 SpecialCharacters 插件,还可指定默认显示的字符组。示例代码:
function mymodule_ckeditor5_plugin_info_alter(array &$plugins) {
  if (isset($plugins['specialCharacters'])) {
    $plugins['specialCharacters']['enabled'] = TRUE;
    // 配置默认加载的字符组,比如数学符号、箭头等
    $plugins['specialCharacters']['configuration']['groups'] = ['math', 'arrows'];
  }
}
  • 自定义字符组:若需新增专属特殊字符,可编写自定义 CKEditor 5 插件,通过 hook_ckeditor5_plugins() 注册插件后,在 JS 代码中扩展 SpecialCharacters 的字符组。
  • 后台配置调整:在 Drupal 文本格式设置中,找到对应 CKEditor 5 编辑器,启用「特殊字符」按钮并添加到工具栏。

二、解决 CKEditorError: plugincollection-plugin-not-found {"plugin":null} 错误

该错误多因自定义插件注册或构建环节出错,按以下步骤排查:

  • 检查插件注册钩子:确保 hook_ckeditor5_plugins() 中插件的 id 与 JS 里注册的插件名称完全一致,class 路径和 library 定义准确。示例:
function mymodule_ckeditor5_plugins() {
  return [
    'mymodule_custom_plugin' => [
      'id' => 'mymoduleCustomPlugin', // 必须匹配JS插件名
      'class' => '\Drupal\mymodule\Plugin\CKEditor5Plugin\MyCustomPlugin',
      'library' => 'mymodule/ckeditor5.custom_plugin',
      'label' => t('My Custom Plugin'),
      'elements' => [],
    ],
  ];
}
  • 验证构建文件:确认 yarn run build 生成的编译后 JS 文件(通常在 js/build/ 目录)已正确生成,且模块的 libraries.yml 正确引用:
ckeditor5.custom_plugin:
  js:
    js/build/custom-plugin.js: {}
  dependencies:
    - ckeditor5/ckeditor5
    - core/drupal
  • 检查 JS 插件代码:确保插件正确继承 CKEditor 5 的 Plugin 类,且注册名称与钩子一致。示例:
import { Plugin } from 'ckeditor5/src/core';

export default class MyCustomPlugin extends Plugin {
  static get pluginName() {
    return 'mymoduleCustomPlugin'; // 与PHP钩子id一致
  }

  init() {
    // 插件初始化逻辑
  }
}

ClassicEditor.builtinPlugins.push(MyCustomPlugin);
  • 清除缓存:执行 drush cr 或后台清除所有缓存,确保新配置被加载。
  • 检查模块依赖:确认 .info.yml 中已声明依赖 ckeditor5:
name: 'My Custom Module'
type: module
description: 'Custom CKEditor 5 plugin for Drupal'
core_version_requirement: ^9 || ^10
dependencies:
  - ckeditor5:ckeditor5

内容的提问来源于stack exchange,提问作者Lukáš Sýkora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 03:15:38