XF 2.0 Remove Editor Buttons

AndyB

Well-known member
I have an add-on called "Remove Editor Buttons" for XF1.

https://xenforo.com/community/resources/remove-editor-buttons.3628/

I would like to update this add-on to XF2 but I'm not finding a simple solution. It appears currently there's no way to add CSS to hide editor toolbar buttons. So far the only way I'm able to hide any of the editor toolbar buttons is to hack the editor.js file directly by removing the button name.

js/xf/editor.js

Code:
		getButtonConfig: function()
		{
			var buttons =
				'clearFormatting,|,bold,italic,underline,strikeThrough,'
				+ '|,color,fontFamily,fontSize,'
				+ '|,insertLink,insertImage,xfSmilie,xfInsert,'
				+ '|,xfCustomPlaceholder,'
				+ '|,align,xfList,'
				+ '|,undo,redo,'
				+ '|,xfDraft,xfBbCode';

			var buttonClass = {
				_basic: ['bold', 'italic', 'underline', 'strikeThrough'],
				_extended: ['color', 'fontFamily', 'fontSize'],
				_link: ['insertLink'],
				_align: ['align'],
				_list: ['formatOL', 'formatUL', 'outdent', 'indent'],
				_indent: ['outdent', 'indent'],
				_smilies: ['xfSmilie'],
				_image: ['insertImage'],
				_media: ['xfMedia'],
				_block: ['xfQuote', 'xfCode', 'xfSpoiler']
			};

Hopefully there's an easy solution so an add-on can be created that allows selecting which buttons to remove.
 
Can you use:
CSS:
button#fontSize-1 {
        display: none;
}

Works for me in the browser tools.
View attachment 156093

Hi Steve,

I tried that before creating this thread and it doesn't work for me. I put that CSS code into the extra.less template and the button still shows, yes I reloaded the page. I tried Firefox and Chrome, I'm using macOS.
 
Thanks to Chris' suggestion I've made some progress. If I add this line of code to the forum_post_thread template:

data-buttons-remove="{$disabledButtons|join(',')}"

Code:
				<xf:editorrow name="message" value="{{ $post.message ?: $forum.draft.message }}"
					rowtype="fullWidth noLabel mergePrev"
					data-buttons-remove="{$disabledButtons|join(',')}"
					label="{{ phrase('message') }}" />

that works great as long as I define $disabledButtons as the following array:

$disabledButtons = array('_extended','_align','_indent');

My question is there any way to define $disabledButtons in the template? Or do I have to define it in PHP and make the variable available in those templates the editor is used?
 
Sorry to hijack this thread, but I would like to instead add some custom buttons to our editor, it's mostly some of our custom bbcodes that I would like to "promote" directly in the editor. How should I do that?
 
Sorry to hijack this thread, but I would like to instead add some custom buttons to our editor, it's mostly some of our custom bbcodes that I would like to "promote" directly in the editor. How should I do that?
Just set an editor icon in the options for the custom BBcodes.
 
Unfortunately I don't see any way to set a display order on the custom buttons. Might be worth suggesting, as that's definitely a bit frustrating.
 
on similar topic, is it now possible to take out the quote button and place it on the main toolbar? can i create a custom bbcode and add it like suggested above?
 
I don't think so, custom BBCodes are for creating new BBCodes and not modifying core ones. There's no way that I'm aware of to change the default button placement, short of manually editing the JS (which is probably a bad idea).
 
i was talking about replicating the quote bbcode functionality instead of modifying the existing one :P put a new one on the main toolbar if a copy can be created using this feature!
 
It does seem you can create custom BBCodes that override the core ones. You could maybe setup a callback with something like this (untested, there may be other considerations to watch out for):
PHP:
public static bbCodeQuote(
    $tagChildren,
    $tagOption,
    $tag,
    array $options,
    \XF\BbCode\Renderer\AbstractRenderer $renderer
) {
    return $renderer->renderTagQuote($tagChildren, $tagOption, $tag, $options);
}
 
Top Bottom