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

Patterns should not display if their blocks are not allowed #23275

Closed
Tracked by #31153
chrisvanpatten opened this issue Jun 18, 2020 · 8 comments · Fixed by #30300 or #30366
Closed
Tracked by #31153

Patterns should not display if their blocks are not allowed #23275

chrisvanpatten opened this issue Jun 18, 2020 · 8 comments · Fixed by #30300 or #30366
Assignees
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@chrisvanpatten
Copy link
Member

Describe the bug
In the current version of Gutenberg (8.3.0) and several earlier versions, block patterns display even if the blocks they are composed of are not "allowed" on the post type (via the allowed_block_types filter). Patterns should be hidden if they are composed of disallowed blocks.

To reproduce
Steps to reproduce the behavior:

  1. Create a post type
  2. Use allowed_block_types filter to limit blocks down to one or two
  3. Observe patterns displaying

Expected behavior
Patterns should only display if all their constituent blocks are available.

Screenshots
Screen Shot 2020-06-18 at 8 58 18 AM

@chrisvanpatten chrisvanpatten added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Jun 18, 2020
@chrisvanpatten
Copy link
Member Author

There might also be an intersection with template_lock; if you have the inserter open at the top level of a post which is template locked, the inserter displays "No results found" for the blocks inserter, but the pattern inserter displays all the registered patterns. Then, it still allows you to click to insert but in fact the pattern is not inserted because of the lock. It's a bit of a confusing UX.

@chrisvanpatten
Copy link
Member Author

Here's a brief/blurry demo of what I see:

demo-23275

@chvillanuevap
Copy link

This issue also applies to Reusable Blocks.

@jeremyfelt
Copy link
Member

I needed to solve this for a custom post type of mine and spun off the solution into a standalone plugin: https://github.com/jeremyfelt/unregister-broken-patterns

I don't have enough familiarity with "allowed" vs registered/unregistered block types and how to account for that in thinking of where a solution should be implemented. My guess is that WP_Block_Patterns_Registry::get_instance()->get_all_registered() could be passed a block types array, but it could also go further down in edit-form-blocks.php. 🤷🏻

All in all, +1 for fixing this. :)

@justintadlock
Copy link
Contributor

I literally just came across this issue while testing your Shortnotes plugin, @jeremyfelt. Came here to create a new issue.

@jeremyfelt
Copy link
Member

@justintadlock If you haven't found it yet, this is a plugin in the repo now too: https://wordpress.org/plugins/unregister-broken-patterns

I'm still behind on documenting the quirks. :)

@jeremyfelt
Copy link
Member

Via #30300:

This implementation only works for top-level blocks in patterns. If a pattern contains a block deep inside somewhere in its block tree, then it will still show up in the inserter. We need to recursively check for all blocks in the pattern.

@ntsekouras @david-szabo97 This ticket was auto-closed when #30300 was merged. Can it be reopened until a more complete solution is in place? Thanks!

@melcarthus
Copy link

melcarthus commented Nov 9, 2023

I move my comment here -> #31706 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
7 participants