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

Block patterns: hide sidebar when no patterns are registered #20867

Closed
Tracked by #31153
simison opened this issue Mar 13, 2020 · 10 comments
Closed
Tracked by #31153

Block patterns: hide sidebar when no patterns are registered #20867

simison opened this issue Mar 13, 2020 · 10 comments
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Bug An existing feature does not function as intended

Comments

@simison
Copy link
Member

simison commented Mar 13, 2020

Describe the bug
When there are 0 block patterns registered, the sidebar shows up empty:

screenshot-2020-03-13-at-12 03 56

Kudos @akirk for spotting.

To reproduce
Steps to reproduce the behavior:

  1. Unregister all block patterns (@akirk do you have code at handy to do this?)
  2. Open block patterns sidebar
  3. Observe empty sidebar

Expected behavior
No block pattenrs sidebar available.

@simison simison added [Type] Bug An existing feature does not function as intended [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Mar 13, 2020
@akirk
Copy link
Member

akirk commented Mar 13, 2020

Unregister all block patterns

On the PHP side it can be done with this snippet:

function disable_block_patterns( $settings ) {
	unset( $settings['__experimentalBlockPatterns'] );
	return $settings;
}
add_filter( 'block_editor_settings', 'disable_block_patterns', 100 );

@mtias
Copy link
Member

mtias commented Mar 13, 2020

This is temporary UI, I don't think it's worth handling this. It should be easy to unregister the whole patterns plugin if that's what you want to do.

@akirk
Copy link
Member

akirk commented Mar 13, 2020

It should be easy to unregister the whole patterns plugin if that's what you want to do.

Could you give some guidance here? I see the BlockPatterns loading is hardcoded here: https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/plugins/index.js#L17

@mcsf
Copy link
Contributor

mcsf commented Mar 13, 2020

This is temporary UI, I don't think it's worth handling this. It should be easy to unregister the whole patterns plugin if that's what you want to do.

Should we pluck BlockPatterns into its own plugin? The following allows disabling of patterns via wp.plugins.unregisterPlugin( 'edit-post-block-patterns' ):

diff --git a/packages/edit-post/src/plugins/index.js b/packages/edit-post/src/plugins/index.js
index 87853d4493..a821d53366 100644
--- a/packages/edit-post/src/plugins/index.js
+++ b/packages/edit-post/src/plugins/index.js
@@ -16,11 +16,20 @@ import ToolsMoreMenuGroup from '../components/header/tools-more-menu-group';
 import WelcomeGuideMenuItem from './welcome-guide-menu-item';
 import BlockPatterns from './block-patterns';
 
-registerPlugin( 'edit-post', {
+registerPlugin( 'edit-post-block-patterns', {
 	render() {
 		return (
 			<>
 				<BlockPatterns />
+			</>
+		);
+	},
+} );
+
+registerPlugin( 'edit-post', {
+	render() {
+		return (
+			<>
 				<ToolsMoreMenuGroup>
 					{ ( { onClose } ) => (
 						<>

@mtias
Copy link
Member

mtias commented Mar 13, 2020

Yes, I thought that was the case already.

@mcsf
Copy link
Contributor

mcsf commented Mar 13, 2020

Ready for review in #20871

@youknowriad
Copy link
Contributor

The plugin approach is also temporary as I was planning to work on the patterns inserter UI and we'll most likely need a way to hide patterns there if no patterns found.

@mcsf
Copy link
Contributor

mcsf commented Mar 13, 2020

The plugin approach is also temporary as I was planning to work on the patterns inserter UI

Yes, I stated this in in #20871, but I don't think it precludes the proposed improvement (IMO it should have been done this way from the start).

@paaljoachim
Copy link
Contributor

paaljoachim commented Apr 15, 2021

I am wondering if this issue is still valid or if it needs updating?
Is there anything here or in associated issues/PRs that contains information that should be added to the Block Editor Handbook?

Perhaps there should be a way through preferences to hide Patterns?

@priethor priethor mentioned this issue Apr 23, 2021
22 tasks
@ntsekouras
Copy link
Contributor

This should be fixed with: #31687.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants