-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation block: allow extending the list of allowed inner blocks #31387
Comments
Good ticket. There's some overlap with #23745, perhaps specifically it's sort of blocked until we can take a stab at that one since the interface and rendered markup needs to be able to handle the added blocks available. Here's an exploration of what happens if we just allow other blocks inside, and here's a mockup of future menu editing. |
Would it make sense for the mini-cart case to define |
I wasn't aware that this option would work, thanks! It seems to work with Gutenberg The only issue of this approach, is that it doesn't allow blocks to be added inside the navigation and outside of it. Ie: a Product Search block could be displayed as part of the navigation or as a widget in the sidebar. |
It's an array so you could define several parent blocks where it can be inserted: "parent": [ "core/navigation", "something/else" ], We discussed that the current implementation is very strict, and it would be great to provide a way to support also "grandparents, "grandgrandparent", and so on 😄 Related issue: #30679. |
By the way, this is how allowed blocks are handled for the Columns block with gutenberg/packages/block-library/src/column/block.json Lines 16 to 18 in 01ac2cf
Related PR: #35342. |
Thanks for the links @gziolo!
That wouldn't still work for the usecase of the a block that I want to make available inside the Navigation block + anywhere else like the Product Search block, right? Or is there a way to say that any parent is allowed (something like |
No, you need to list all parent blocks you want to support. It should be more flexible. |
Can we just add a filter hook? ...
allowedBlocks: wp.hooks.applyFilters( 'navigation_allowed_blocks', ALLOWED_BLOCKS ),
... But it would be cool to have full control over the whole menu and stop limiting block, because then you can create megamenus and more complex structures... |
We discuss finding a general solution to customize the list of allowed blocks for inner blocks with block attributes in #15682. So far, the handling was added whenever it was requested for blocks with inner blocks. You can see it in action for the following core blocks:
It should be fine to replicate the same approach for the Navigation block, too. It's something we definitely should support by default whenever there are inner blocks involved, as we do it for the template lock. I'm sure there are more features that would benefit from similar pattern. |
The Nav block has some additional complications in that it actively manages the output of it's inner blocks in the PHP server render of the block.
|
@gziolo I tried your approach of defining However the issue we are now running into is what @getdave described above. The navigation block does some magic to move some inner blocks into a special wrapper. The list of the blocks that get this treatment is again hardcoded in PHP. Ideally I would love for this Array in PHP to either be filterable or for the solution to not check for the block name but instead the markup produced by the block. If the merkup is an |
@fabiankaegy I think a PR which utilises the Tag Processor to find the |
Is this solved by this recent PR that adds an allowedBlocks field to block.json to specify allowed children? #58262 |
Oh yes, that's solved for our use case. I'm going to close this issue. Thanks for the heads-up, @annezazu! |
The Navigation block has a hard-coded list of allowed inner blocks:
gutenberg/packages/block-library/src/navigation/edit.js
Lines 32 to 38 in d77994e
But plugins might want to add more blocks to that list. For example, WooCommerce could add a Product Search block or a minicart block (ie: a link to the Cart which shows the number of products in the cart).
If I'm not wrong, there is no way plugins can do that right now, so this issue is about making the
ALLOWED_BLOCKS
list filterable or introducing some other API so plugins can extend the list of allowed blocks inside the Navigation block.The text was updated successfully, but these errors were encountered: