gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Setting 'parent' restriction in block API (block metadata) does not prevent the block from being transformed (wrapped) by group and column blocks.

Open wwdes opened this issue 2 years ago • 2 comments

Description

The parent block API is not being honored by the transform options "Columns" and "Group" (and "Details" with Gutenberg plugin 19.5.0). According to block API reference: "Setting parent lets a block require that it is only available when nested within the specified blocks."

Step-by-step reproduction instructions

Set a custom block's parent metadata key to a specific parent block:

{ "parent": [ "core/cover" ] }

In the editor, create the cover block and insert your custom block. While selecting your custom block, click on the button that has the blocks icon in the floating toolbar to get the transform options. There are seen buttons: "Columns" and "Group" (and "Details" with Gutenberg plugin 19.5.0). When user clicks either of them, the custom block is now wrapped within the corresponding block, bypassing the restriction set by the parent block API.

Screenshots, screen recording, code snippet

No response

Environment info

Tested on WP 6.6.2 without Gutenberg plugin as well as with Gutenberg plugin 19.5.0.

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

  • [x] Yes

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

  • [x] Yes

Please confirm which theme type you used for testing.

  • [x] Block
  • [ ] Classic
  • [ ] Hybrid (e.g. classic with theme.json)
  • [ ] Not sure

wwdes avatar Oct 31 '24 16:10 wwdes

@wwdes @gziolo I was able to replicate the issue.

Upon investigating, I believe the problem lies in how we are retrieving the BlockTypes for possible transformations here. The group, details, and columns blocks are unique because they can wrap any block as a transformation target.

If we want to prevent this behavior, we could add a filter to allow only parent/ancestor blocks when the parent/ancestor property is set.

However, I don't think this would be the ideal solution, as it would remove the default group transformation option for blocks with the parent value set.

What do you all think about this approach?

nani-samireddy avatar Jan 09 '25 16:01 nani-samireddy

I am currently working on a custom block and had the same problem. Seems to be a very fundamental functionality for me. Would be really grateful for a fix.

silaskoehler avatar Jun 16 '25 10:06 silaskoehler