-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Allow the specification of blocks allowed within columns #25778
Conversation
Sync with master repo
Update branch with new master from gutenberg
Reopening this one. |
Tested and confirmed this works, details on #25183 (comment) |
Hi! I was wondering if there was any progress on this? Or if it was merged in part of another PR? The last commits is dated of October 23rd, it was confirmed as working but the merge is blocked because of failed checks. I've looked around quit a bit and this is the most recent and up to date PR I've seen concerning the issue of allowed blocks in column elements. |
@JesserH could you please sync your fork with the main repo? I believe most of the failing tests have been fixed since then |
I was wondering if it'd be possible to use block context to just declare the attribute once on the parent columns block: The individual column could consume that context and pass it to the inner blocks of the column. This way there would be a single source of truth for the |
Though I've maybe changed my mind looking at how the It seems like that PR specifically went for a solution where columns could have different template lock settings. It didn't really tackle whether users could modify the column count after the fact. Given the main use-case for both would be templating, I wonder if it's worth matching that implementation for consistency as a first step, and then considering how it might work in the columns block as a separate change. What do you think? |
@talldan I chose to implement the allowedChildBlocks for the blocks individually because of the columns block which has a slider. To my understanding it's not ideal to pass the value to the new block when the slider is moved upwards (so new blocks spawned). |
@aristath thanks for the follow up on this feature! It seems like the merge is only awaiting your validation for the requested changes. Once it's merged and part of an update (not sure of the flow here) I'll be able to test it and give feedback if I find some problems with it. |
I was part of this feature's development so I can't (ethically) review it, I wouldn't be objective. We'll wait for someone else to properly review it when it's time 👍 |
@@ -72,6 +72,7 @@ function ColumnsEditContainer( { | |||
} ); | |||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | |||
allowedBlocks: ALLOWED_BLOCKS, | |||
allowedChildBlocks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line can be removed, allowedChildBlocks
isn't a recognized property for inner blocks:
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/inner-blocks/README.md#props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree that this line should be removed.
@JesserH From testing, I think function myplugin_register_book_post_type() {
$args = array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true,
'template' => array(
array(
'core/columns',
array(
'allowedChildBlocks' => array( 'core/paragraph' ),
),
array(
array(
'core/column',
),
array(
'core/column',
),
),
),
),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' ); This didn't work, I still need to specify It could be renamed, but I think this needs some more thought. I'd be inclined to strip this PR back to just include the changes to the column block Also cc'ing @jorgefilipecosta and @mcsf for a review, as it looks like Jorge worked on the template lock for column and Miguel code reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the allowedBlocks attribute in columns is good addition, it follows the same approach as in #26128 👍
Regarding the mechanism to control allowed blocks for newly created columns I agree with @talldan, it seems safer to not include it for now.
I guess if we needed it after we can create something with specific names saying that is for new columns that covers, allowedBlocks and templateLock.
@@ -72,6 +72,7 @@ function ColumnsEditContainer( { | |||
} ); | |||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | |||
allowedBlocks: ALLOWED_BLOCKS, | |||
allowedChildBlocks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree that this line should be removed.
@jorgefilipecosta I updated the PR accordingly 😄 |
@JesserH The changes seem the opposite to what was recommended, I think it'd be best to keep only the changes on the column block. |
@talldan Sorry, that's my bad 😅 . I have updated the PR 😄 |
Any update to this? Would be really great to have this feature! 🙏🏼 😬 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is updated according to the requested changes now, right @talldan?
@@ -67,6 +72,7 @@ function ColumnEdit( { | |||
} ); | |||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | |||
templateLock, | |||
allowedBlocks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when allowedBlocks
is undefined?
Unfortunately we can't push any fixes or update the PR since it's on a fork, and @JesserH has since moved on to other projects. |
Description
This an updated version of #25183.
I and @aristath developed a solution to the issue where an individual column could not define any specifically allowed blocks to be added in it. This also applies to newly added columns in the columns block (from the slider at the columns settings) also specify the blocks allowed to be added into that column. We believe that this is important to custom Gutenberg block development to nest blocks in a good and effective way.
How has this been tested?
Me and @aristath have tested this locally.
Screenshots
Types of changes
We have added a new attribute called allowedBlocks in the column, and a childAllowedBlocks attribute within the columns block, which allows for defining the allowed blocks per individual column.
Example of use:
Checklist:
fixes #18161