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

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

Open
3 of 6 tasks
wwdes opened this issue Oct 31, 2024 · 1 comment
Labels
[Feature] Block Transforms Block transforms from one block to another [Type] Bug An existing feature does not function as intended

Comments

@wwdes
Copy link
Contributor

wwdes commented Oct 31, 2024

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.

  • Yes

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

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@wwdes wwdes added the [Type] Bug An existing feature does not function as intended label Oct 31, 2024
@gziolo gziolo added the [Feature] Block Transforms Block transforms from one block to another label Nov 1, 2024
@gziolo gziolo mentioned this issue Nov 1, 2024
69 tasks
@nani-samireddy
Copy link

nani-samireddy commented Jan 9, 2025

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Transforms Block transforms from one block to another [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants