-
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
Add allowedBlocks and TemplateLock attributes in Cover Block #31326
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @ajotka! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
@@ -306,6 +306,8 @@ function CoverEdit( { | |||
minHeightUnit, | |||
style: styleAttribute, | |||
url, | |||
allowedBlocks, | |||
templateLock = false, |
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.
Setting a default here explicitly removes the locking even if the attribute is unset causing a behavior change. I think we should not include the default here.
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.
Same default is in Column PR: https://github.com/WordPress/gutenberg/pull/25778/files
Maybe there is no problem, but I prefer to inform you.
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.
The default value has been removed.
Add an option to pass allowedBlocks to Cover Block. Usage: [ 'core/cover', { allowedBlocks: ALLOWED_BLOCKS, templateLock: "insert", }, [] ], Feature from WordPress#31312
85b313b
to
b435d27
Compare
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.
This looks good.
I tested using a block filter to restrict what could be added.
wp.hooks.addFilter(
'blocks.registerBlockType',
'mkaz/testing-cover',
function( settings, name ) {
if ( name != 'core/cover') {
return settings;
}
return {
...settings,
attributes: {
...settings.attributes,
allowedBlocks: {
type: "array",
default: [ 'core/paragraph', 'core/image' ],
},
}
}
}
);
This worked as expected with and without a templateLock value.
Thanks for the contribution! 👍
Congratulations on your first merged pull request, @ajotka! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
I think this is just a quick fix for the cover block. This feature is also useful for many other blocks. Maybe we should add it automatically via PHP to the Block API? |
Description
According to #31312 request, I added allowedBlocks attribute for Cover Block.
How has this been tested? And Screenshots
Tested manually.
With
allowedBlocks = [ 'core/paragraph', 'core/heading', 'core/button' ]
Expectations: Possibility to add only Paragraph, Heading and/or Button
With templateLock
Expectations: No 'add block' button and no possibility to add block
Types of changes
block.json
false
) attributes to edit.jsChecklist:
*.native.js
files for terms that need renaming or removal).