我想通了,希望这对其他人有帮助。
我在我的管理子主题中添加了以下内容,以向摘要文本区域添加一个类:
function adminimal_sub_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node']) && $form['#node']->type == 'article') {
// Add class to body textarea for various content types. This is used for the Ckeditor wordcount plugin to target summary textarea.
$form['body']['und']['0']['summary']['#attributes']['class']['0'] = 'article-summary';
}
}
然后下载 Ckeditor 4 Wordcount 插件并将其保存在插件目录(sites/all/libraries/ckeditor/plugins)中。
在 Drupal UI 中,我转到配置 > CKEditor Filtered HTML (edit) 并在高级选项下的自定义 Javascript 配置中,我添加了一个路径到我的 ckeditor.config.js (config.customConfig = '/sites/all/themes/global/ js/ckeditor.config.js';)。
这是我的 ckeditor.config.js:
CKEDITOR.editorConfig = function(config) {
if (this.element.hasClass('article-summary')) {
config.wordcount = {
showCharCount: true,
maxCharCount: 170
}
}
// Make CKEditor's edit area as high as the textarea would be.
if (this.element.$.rows > 0) {
config.height = this.element.$.rows * 20 + 'px';
}
}
在这里我可以设置 maxwordcount 并加载更多,但是对于这个项目只需要 maxwordcount。这样,如果 Drupal Ckeditor 模块得到更新,这个文件将不会受到影响。