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

Add option to block API to only allow root level insertion #42548

Closed
fabiankaegy opened this issue Jul 20, 2022 · 3 comments
Closed

Add option to block API to only allow root level insertion #42548

fabiankaegy opened this issue Jul 20, 2022 · 3 comments
Labels
Developer Experience Ideas about improving block and theme developer experience [Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Enhancement A suggestion for improvement. [Type] New API New API to be used by plugin developers or package users.

Comments

@fabiankaegy
Copy link
Member

What problem does this address?

There are instances where a block should only ever exist at the root level of the block editor. It should never be nested within a Group or any other InnerBlocks area. Examples of this are things like the Page Header Template Part. Also when building custom blocks this is something that comes up here and there.
Often this is best paired with the supports.multiple option set to false so an editor can only insert the block once at the root level

What is your proposed solution?

Add a new Block Supports option that is essentially the opposite of ancestor or parent. Maybe it could even use the parent key just set to false.

@fabiankaegy fabiankaegy added [Type] Enhancement A suggestion for improvement. [Feature] Block API API that allows to express the block paradigm. Developer Experience Ideas about improving block and theme developer experience [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] New API New API to be used by plugin developers or package users. labels Jul 20, 2022
@gziolo
Copy link
Member

gziolo commented Jul 20, 2022

@fabiankaegy, thank for raising the issue. It would be great to double check if we already have something similar tracked in #41236. Otherwise we should add it to the list of tasks there.

Add a new Block Supports option that is essentially the opposite of ancestor or parent. Maybe it could even use the parent key just set to false.

It would be interesting to explore whether we can have more options for the parent and ancestor fields like:

In general, we would benefit of having a simple way to express that a given block should be available only for a given post type or template type. I'm positive that we can avoid introducing another field in Block API to fulfil the requirements.

@fabiankaegy fabiankaegy mentioned this issue Jul 20, 2022
67 tasks
@donnapep
Copy link
Contributor

I have a possible use case that might benefit from something like this.

I'm creating a block that can be used standalone on a custom post type, and also as an inner block of another block that is only available on pages. What I'd like to be able to do is display the block in the inserter of the custom post type, but not display it in the inserter of a page. Removing it from the block inserter is normally handled by adding a parent attribute, but since this block is both an inner block and also not, depending on context, that approach doesn't really work.

@fabiankaegy
Copy link
Member Author

This is now possible by setting the parent to core/post-content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Enhancement A suggestion for improvement. [Type] New API New API to be used by plugin developers or package users.
Projects
None yet
Development

No branches or pull requests

3 participants