Silverstripe 4 TinyMCE characters count
, (*1)
Installation
composer require drmartingonzo/ss-tinymce-charcount ^1.1.0
, (*2)
Requirements
Enable plugin
In your _config.php file, add :, (*3)
use SilverStripe\Forms\HTMLEditor\HtmlEditorConfig;
use SilverStripe\Core\Manifest\ModuleResourceLoader;
Then add whatever plugins you wish to enable, + charcount, (*4)
HtmlEditorConfig::get('cms')
->enablePlugins([
'template',
'fullscreen',
'hr',
'contextmenu',
'charmap',
'visualblocks',
'lists',
'charcount' => ModuleResourceLoader::resourceURL('drmartingonzo/ss-tinymce-charcount:client/dist/js/bundle.js'),
])
Finally run dev/build
with flush to remove previous TinyMCE javascript cache., (*5)
Adding a max character attribute to a TinyMCE instance
Set data-maxchar
on HTMLEditorField.
Example :, (*6)
HTMLEditorField::create(
"Content",
'Content'
)->setAttribute('data-maxchar', 526),
Adding a max word attribute to a TinyMCE instance
Set data-maxword
on HTMLEditorField.
Example :, (*7)
HTMLEditorField::create(
"Content",
'Content'
)->setAttribute('data-maxword', 120),