Skip to content

Conversation

@gaambo
Copy link
Contributor

@gaambo gaambo commented Apr 21, 2023

What?

Adding the allowedBlocks attribute to the core/media-text block and pass it into the innerBlockProps to be considered by the InnerBlocks component

Why?

Being able to constraint the allowedBlocks for a media-text block from an InnerBlocks template is useful for patterns in controlled/restricted designs. See #15682.
This mechanism is already used in core/group (#49128), core/cover and core/column.

How?

Testing Instructions

Positive Test

  1. Create a new post and insert the Media and Text block.
  2. Set the allowedBlocks attribute of this group to an array containing core/paragraph. Eg allowedBlocks":["core/paragraph"]
  3. Check that in the editor, only paragraph blocks can be added as inner blocks to the Media and Text Block

Test block (media needs to be replaced):

<!-- wp:media-text {"mediaId":8,"mediaLink":"http://localhost:8888/?attachment_id=8","mediaType":"image","allowedBlocks":["core/paragraph"]} -->
<div class="wp-block-media-text is-stacked-on-mobile"><figure class="wp-block-media-text__media"><img src="http://localhost:8888/wp-content/uploads/2023/04/ros-buehne-1001900x400-1-1024x216.jpg" alt="" class="wp-image-8 size-full"/></figure><div class="wp-block-media-text__content"></div></div>
<!-- /wp:media-text -->

Negative Test

  1. Create a new post and insert the Media and Text block.
  2. Check that all blocks can be inserted as inner blocks

Testing Instructions for Keyboard

Screenshots or screencast

@gziolo gziolo added [Block] Media & Text Affects the Media & Text Block [Type] Enhancement A suggestion for improvement. labels Apr 21, 2023
@gziolo gziolo requested a review from Mamaduka April 21, 2023 13:27
@Mamaduka Mamaduka changed the title Add allowedBlocks to innerBlocks of Media & Text block #15682 Media & Text: Add allowedBlocks attribute and pass it to innerBlock #15682 Apr 24, 2023
@Mamaduka Mamaduka changed the title Media & Text: Add allowedBlocks attribute and pass it to innerBlock #15682 Media & Text: Add allowedBlocks attribute and pass it to innerBlock Apr 24, 2023
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @gaambo!

The changes work as expected!

@Mamaduka Mamaduka merged commit 744ba04 into WordPress:trunk Apr 25, 2023
@github-actions github-actions bot added this to the Gutenberg 15.7 milestone Apr 25, 2023
@gaambo gaambo deleted the gaambo/add-allowedblocks-media-text-15682 branch April 25, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Media & Text Affects the Media & Text Block [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants