-
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
Blocks: Deprecate registerBlockTypeFromMetadata
in favor of registerBlockType
#32030
Blocks: Deprecate registerBlockTypeFromMetadata
in favor of registerBlockType
#32030
Conversation
49d7420
to
9334ff2
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.
I like the consolidation
} | ||
|
||
if ( isObject( blockNameOrMetadata ) ) { | ||
unstable__bootstrapServerSideBlockDefinitions( { |
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 just fills serverSideBlockDefinitions
that is used a few lines under right? In theory we could avoid it here right?
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.
In the future, we could. At the moment it contains some backward compatibility logic for apiVersion
.
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.
gutenberg/packages/blocks/src/api/registration.js
Lines 174 to 185 in 298f508
// We still need to polyfill `apiVersion` for WordPress version | |
// lower than 5.7. If it isn't present in the definition shared | |
// from the server, we try to fallback to the definition passed. | |
// @see https://github.com/WordPress/gutenberg/pull/29279 | |
if ( | |
serverSideBlockDefinitions[ blockName ].apiVersion === | |
undefined && | |
definitions[ blockName ].apiVersion | |
) { | |
serverSideBlockDefinitions[ blockName ].apiVersion = | |
definitions[ blockName ].apiVersion; | |
} |
Size Change: +83 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
registerBlockType now accepts input from the block.json metadata WordPress/gutenberg#32030
…ofhouse * @wordpress/blocks: Register block from metadata registerBlockType now accepts input from the block.json metadata WordPress/gutenberg#32030 * Derive example attributes from block #55245 (comment) * Stronger typing for example/innerBlocks #55245 (comment) * Provides stronger typings for providesContext #55245 (comment) * Rename generic type from T -> TAttributes #55245 (comment) * Derive innerBlocks from Block properties #55245 (comment) * Reuse block props in example * Make innerBlocks in example optional
Description
Props to @mtias for the proposal. Rather than using two distinct methods to register block types in the block editor, let's make
registerBlockType
the canonical method to deal with all use cases. In practice, the PR proposed extends its usage to work as a proxy the formerregisterBlockTypeFromMetadata
. It should remove some confusion that we observed and let us be more explicit what's the latest recommendation. It will also allow us to better communicate what's the preferred way to register block types in the context of WordPress.We have already applied a similar change in WordPress core:
WordPress/wordpress-develop@6ad4e34
Dev Note
This is the updated note from #30293:
In JavaScript, you can use now
registerBlockType
method from@wordpress/blocks
package to register a block type using the metadata loaded fromblock.json
file. All localized properties get automatically wrapped in_x
(from@wordpress/i18n
package) function calls similar to how it works in PHP withregister_block_type
. The only requirement is to set thetextdomain
property in theblock.json
file.Example:
block.json
index.js
How has this been tested?
Unit tests were updated.
I also tested deprecations for
wp.blocks.registerBlockTypeFromMetadata
in the Browser Console:Screenshots
Types of changes
API change and deprecation.
Checklist:
*.native.js
files for terms that need renaming or removal).