-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Request a hook that can change the default value of the block manager. #40605
Comments
@shimotmk Would you be able to share some more information on what your use case is for making a block hidden by default? Is this to hide core blocks or other blocks? I think you can already filter
|
@talldan function filter_block_editor_settings_when_post_provided( $editor_settings, $editor_context ) {
if ( ! empty( $editor_context->post ) ) {
$editor_settings['allowedBlockTypes'] = array( 'core/heading','core/quote', 'core/table');
}
return $editor_settings;
}
add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_when_post_provided', 10, 2 ); But what I want to do is change the default value of the block manager. The use case is that I want to use it to deprecate custom blocks as Gutenberg evolves. |
My understanding of
I think this is a little tricky to achieve with how the block manager is implemented right now. Currently, there's a const hiddenBlockTypes = [ 'core/table' ]; If it were possible to provide a default, it might look something like const defaultHiddenBlockTypes = [ 'core/table', 'core/quote' ]; But a user making one of those defaults visible means removing it from the Let me know if you have any ideas. |
@talldan It is still difficult with the current code. const hideBlockArray = [ 'core/heading','core/quote','core/table'];
wp.data.dispatch('core/edit-post').hideBlockTypes(hideBlockArray) to be executed only once when the block editor is displayed. |
The underlying data for hidden blocks was recently rearranged a bit and moved to the That store does have an API for defaults: wp.data.dispatch( 'core/preferences' ).setDefaults( 'core/edit-post', 'hiddenBlockTypes', [ 'core/heading','core/quote','core/table'] ); But this default is only applied when gutenberg/packages/preferences/src/store/selectors.js Lines 11 to 14 in f2124de
It wouldn't work the way you want it to, but it'd be nice if this existing API did work. I haven't been able to think of a way to do that. BTW, no need to close the issue, it can stay open while we continue to think about options. |
Seems to me that With the block manager show/hide blocks in the inserter now is a user setting. Why isnt this stored in the usermeta table in the database? And why should a user (my clients) be bothered with packs of useless embed-blocks all turned on (default visible)? I know I can disable blocks the hard way by php filtering, but thats not the right way to hide blocks because you get errors when a block is used before setting this filter. I thing there should be a 'overall hide function' (like it was) to hide blocks from the inserter AND block manager. |
We've started saving values in the |
Hi there.
What problem does this address?
I want to change the default value of the block manager.
I want to change the default value of the block manager instead of turning off block registration with
unregisterBlockType
, etc.because we want to leave the ability to turn off blocks to the user.
It turns out that you can add a hide block by specifying it like this.
However, this will restore the turned off blocks when reloading assuming they are turned on.
block.manager.mov
What is your proposed solution?
defaultAllowedBlockTypes
gutenberg/packages/edit-post/src/components/block-manager/category.js
Line 23 in b6c79fe
Could you please add a filter hook here?
That would help the custom block developer by allowing him to change the default values.
Thank you.
The text was updated successfully, but these errors were encountered: