Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is a plugin for the ckeditor module that allows for a word count function:
#764014: Word Count Plugin
Can we get it so this works with ckeditor in wysiwyg module?
How can I help towards achieving this?
Comments
Comment #1
TwoDWe will most likely not include direct support of 3rd party plugins in Wysiwyg itself, we've wouldn't have time to keep up with them all.
Instead, Wysiwyg has a hook for describing editor plugins called hook_wysiwyg_plugins(). It's described in wysiwyg.api.php and all you need to do is to implement it in a small Drupal module, like this:
sites/default/modules/MYMODULE/MYMODULE.info
sites/default/modules/MYMODULE/MYMODULE.module
Then extract the plugin to sites/all/libraries/ckeditor_plugins/wordcount.
That will make Wysiwyg put a "Word Count" checkbox in the "Buttons and Plugins" list and include the plugin when the checkbox is checked. I put the plugin outside the CKEditor path and point there using the 'path' key above so I can upgrade CKEditor without worrying about reinstalling the plugin. However, there's a chance the plugin might not tolerate this (it can use relative paths to refer to CKEditor's files etc), so you can place it in the ckeditor/plugins path if you also remove the above 'path' key and switch the 'internal' key to TRUE.
Now, this plugin also uses a new element to actually show the word limit in. You could probably add that using hook_form_alter(), making sure it begins with the same name as the field, to all fields where you need it. That might get troublesome in the long run, so it might be better to implement hook_element_info(), add another '#pre_render' callback to the 'text_format' element type and injects the hidden field from there. Looking through wysiwyg_pre_render_text_format() should give you some hints to when and how Wysiwyg determines when to include the editor code, in case you don't want the hidden field to show up when it's not going to be used.
Also note that a couple of bugs in this plugin have been mentioned over at http://www.n7studios.co.uk/2010/03/01/ckeditor-word-count-plugin/ so it might not work as expected when there are multiple editors on the page or when instances are removed.
Comment #2
MurzAlso you can look to my version of character counter plugin: https://github.com/MurzNN/ckeditor-characterscount
Comment #3
TwoDClosing this as "fixed" to clean up the queue a bit. Please change back to "active" if you encounter problems.
Comment #4
yanniboi CreditAttribution: yanniboi commentedNo problem @TwoD. Thanks for the advice!
Comment #6
ggevalt CreditAttribution: ggevalt commentedThanks so much for your effort on this...
Do you have a wysiwyg 6.x version of this?
Thanks so much in advance,
g