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

Cannot disallow block without disallowing block variations #51112

Open
CodeProKid opened this issue May 30, 2023 · 5 comments
Open

Cannot disallow block without disallowing block variations #51112

CodeProKid opened this issue May 30, 2023 · 5 comments
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Enhancement A suggestion for improvement.

Comments

@CodeProKid
Copy link

Description

I have a use case where I want to disallow a block from being added to the editor, but not the variations of the block. The two approaches I tried to make this work were by removing the block from the allowedBlocks passed in to the editor instance, and by setting the inserter support to false on the block. Unfortunately it looks like when the inserter determines which blocks & variations are eligible for insertion it won't make that determination against each variation individually if the block type is not eligible for insertion.

Step-by-step reproduction instructions

  1. Set the inserter supports flag to false on a component with block variations
  2. You will see that the block as well as it's variations are no longer able to be added to the editor.

Screenshots, screen recording, code snippet

No response

Environment info

  • @wordpress/block-editor 9.5.0
  • @wordpress/editor 12.0.2
  • @wordpress/components 19.0.1

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@talldan
Copy link
Contributor

talldan commented May 31, 2023

@CodeProKid I would maybe imagine this being possible by removing the inserter scope from an isDefault variation, but I just tried it and it doesn't work. The main block type shows up again in the inserter. That might be a bug, since it feels to me like the isDefault variation should always override the main block type.

The other thing is that there has been some work on adding block supports for variations, and I think that would solve this issue (as supports: { inserter: true/false } would work on the variation itself).

@talldan talldan added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Block Variations Block variations, including introducing new variations and variations as a feature labels May 31, 2023
@talldan
Copy link
Contributor

talldan commented May 31, 2023

I'll cc @ntsekouras who might have some thoughts.

@CodeProKid
Copy link
Author

I would maybe imagine this being possible by removing the inserter scope from an isDefault variation, but I just tried it and it doesn't work.

Ah yeah, I played around with this too and saw the same result. I think having support for this approach makes the most sense to unblock this use case.

Looking at the code, it seems like when we go to grab the block variations, we only get the ones with the inserter scope here, so when we go to replace the main block with the isDefault variation here, it's not in the list of variations.

@ntsekouras
Copy link
Contributor

Thanks for the issue @CodeProKid! I agree with @talldan that probably we need to make new checks about supports: { inserter: true/false }

This is also related to this issue and the solution will probably fix both. This is something that might be more convoluted than it seems, because if we start supporting override of the supports API in block variations, we need to be cautious about the rest of the supports. We could just constraint this to inserter initially, but will need some good thinking for sure.

@CodingSamurai
Copy link

I have a use case that is the inverse where we need the ability to disable block variations but allow access to the base block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants