我使用的是CKEditor - WYSIWYG HTML编辑器Drupal7模块和wordcount插件。我已经在ckeditor plugins目录中添加了wordcount插件文件并使其正常工作,但是我的配置最大字数和字符数等对于所有字段都是相同的。我想为特定字段指定不同的最大字数和字符数。下面是我的配置:
使用CKEDITOR.replace,我做了以下事情:
CKEDITOR.replace('edit-body-und-0-summary',
{
extraPlugins: 'wordcount',
wordcount: {
showCharCount: true,
maxCharCount: 123
}
});这是可行的,但在刷新页面后,它又回到了全局最大字数和字符数。Textrea ID是edit-body-und-0-summary,但此标记在页面中的其他位置重复。
如何将唯一ID添加到文本区域标记中,并对不同字段进行不同的字数统计,例如Summary and Body fields
发布于 2019-12-06 02:10:13
我想通了,希望这能对其他人有所帮助。
我将以下代码添加到Adminimal Sub主题中,以便在摘要文本区域中添加一个类:
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插件,并将其保存在插件目录(site/all/libraries/ckeditor/ plugins )中。
在Drupal UI中,我转到configuration > Javascript Filtered (编辑),在Custom Javascript configuration中的Advanced options下,我添加了一个到我的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模块,该文件也不会受到影响。
https://stackoverflow.com/questions/59037958
复制相似问题