Add a button to TinyMCE

Trying to add a button to the editor for an hr element.

Docs: https://docs.silverstripe.org/en/4/developer_guides/forms/field_types/htmleditorfield/#adding-and-removing-capabilities

So I added to my _config.php file:

use SilverStripe\Forms\HTMLEditor\HtmlEditorConfig;

HtmlEditorConfig::get('cms')->insertButtonsAfter('underline', 'hr');

Did a dev/build flush muck around and no change.

I dumped the value of HtmlEditorConfig::get('cms')->getButtons(); and there is no hr in there.

When I check the value of HTMLEditorConfig::get_active_identifier(); it is “default” not “cms”.

So changed it to: HtmlEditorConfig::get('default')->insertButtonsAfter('underline', 'hr');

flush etc and no change again.

I had a look in vendor/silverstripe/admin/_config.php. and in there they are working with an instance of SilverStripe\Forms\HTMLEditor\TinyMCEConfig;

It’s probably an alias but I changed it anyway:

use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;

TinyMCEConfig::get('cms')->insertButtonsAfter('underline', 'hr');

# and also tried

TinyMCEConfig::get('default')->insertButtonsAfter('underline', 'hr');

and still no hr button.

hr is in the valid_elements array too. Like this: hr[class],

So how the … can I add this button?!

With TinyMCE 4+ the hr is actually a plugin - TinyMCE | Horizontal Rule Plugin

You should be able to try -

TinyMCEConfig::get('cms')->enablePlugins('hr');

Mate! Thank you.
A plugin for 5 characters, wow.

Works with:

use SilverStripe\Forms\HTMLEditor\HtmlEditorConfig;

HtmlEditorConfig::get('cms')->enablePlugins('hr');

HtmlEditorConfig::get('cms')->insertButtonsAfter('underline', 'hr');

HtmlEditorConfig::get('cms')->insertButtonsAfter('hr', 'blockquote');