Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Icons from toolbars of the core blocks #14859

Closed
pwartbichler opened this issue Apr 7, 2019 · 8 comments
Closed

Remove Icons from toolbars of the core blocks #14859

pwartbichler opened this issue Apr 7, 2019 · 8 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@pwartbichler
Copy link

pwartbichler commented Apr 7, 2019

Hi folks,

how would I remove or adapt the toolbars for Gutenberg core blocks? I guess I'd need to use the 'editor.BlockEdit' filter for this but can't wrap my head around it.

Is this the correct way of doing this?

wp.hooks.addFilter(
	'editor.BlockEdit',
	'slug/modify-block-edit',
	modifyBlockEdit
);

function modifyBlockEdit( BlockEdit ) {
	return (props) => {
		if ('core/paragraph' === props.name) {
			const { attributes: { align: false }, setAttributes } = props;
			return (
				<BlockEdit { ...props } />
			);
		}
		return (
			<BlockEdit { ...props } />
		);
	};
}

Sorry for my nooby question and thank you in advance!

Patrik

@pwartbichler
Copy link
Author

Please ignore the code I used above, I was clearly on the wrong track. I now understand that the filter 'editor.BlockEdit' is intended for the contents of the right sidebar. Or am I wrong?

What I do now is that I iterate through all the blocks, trying to disable the toolbars.

Is the correct and recommended approach here that I customize the edit and save method of each block?

@pwartbichler pwartbichler changed the title Remove Icons form toolbars of the core block Remove Icons form toolbars of the core blocks Apr 8, 2019
@randombumper
Copy link

Hi, @pwartbichler. I've been trying to disable text align for core/paragraph, to no avail. I gather from your last comment that you've at least found a workaround. Could you please elaborate on the solution? Thanks!

@pwartbichler
Copy link
Author

My workaround, if one can even call it that, is that I now use css to disable the buttons i don't need. It's really messy, but it works - for now... Sorry for not being able to provide you with a better solution...

@pwartbichler pwartbichler reopened this Apr 26, 2019
@randombumper
Copy link

Well, I find myself doing that a lot in WordPress. Stinky as hell, but as long as a proper solution isn't available...

The problem is, toolbar buttons lack class names (or any other attributes) to identify and hide them. Using position selectors (:nth-child) won't work either, since toolbar positions vary among blocks and depend on configuration.

I have resorted to overwriting text-align properties with !important, so that even if a user tries to align some text to the right it won't affect the output.

@swissspidy swissspidy added [Type] Enhancement A suggestion for improvement. [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] Block API API that allows to express the block paradigm. labels Apr 27, 2019
@pwartbichler
Copy link
Author

@randombumper In my case I am lucky because the client demands that I disable ALL the icons, so the lack of class names is not a problem.
The reason we want to limit the formatting options is because frequently our authors make too much use of them and destroy the look of the frontend (we have around 170 authors).

@pwartbichler
Copy link
Author

@randombumper Maybe this will help you: Link to StackOverflow
The idea behind this solution is to disable the core blocks, make changes to the components, and reactivate them. Unfortunately, this only works for certain elements, not for all, so it didn't really help me.

@randombumper
Copy link

Never thought of that! Thanks for the info. I'll be sure to read the article linked there as well.

@pwartbichler pwartbichler changed the title Remove Icons form toolbars of the core blocks Remove Icons from toolbars of the core blocks Jun 11, 2019
@youknowriad
Copy link
Contributor

Right now, there's no easy solution here. It's hard to find an API that is not adhoc. Let's close this as a duplicate of #6023 which tried to solve the same thing for inspector controls which are not really different from toolbar controls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants