#52138 closed enhancement (fixed)
Editor: Support filtering arguments in block type registration from metadata
Reported by: | gziolo | Owned by: | gziolo |
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | 5.7 |
Component: | Editor | Keywords: | has-patch has-unit-tests needs-dev-note |
Focuses: | Cc: |
Description (last modified by )
Related: https://github.com/WordPress/gutenberg/pull/25220, #49615
With changes added in #49615, it is possible to filter the settings of a block type during its registration with register_block_type_args
. However, when working https://github.com/WordPress/gutenberg/pull/25220, we discovered that it is still not enough for the case when blocks are registered with block.json
metadata. As of today, all core blocks are registered this way and it's impossible to customize the way their styles and scripts are registered or i18n support is handled. The idea here is to add more filters to give more options for plugin authors in the future and account for the needs that Gutenberg has in the constant work to improve the experience around block registration.
The attached patch seeks to follow with 2 new hooks:
- Named
block_type_metadata
to filter the content of metadata read fromblock.json
- Named
block_type_metadata_settings
to filter the settings object determined from the metadata that is passed toregister_block_type
call
I'm 100% sure we need the first one. In terms of adding the second one I'm open to discussion since it might
duplicate the scope of register_block_type_args
with the only difference that it contains also the metadata object as an argument passed for processing.
Change History (8)
This ticket was mentioned in PR #821 on WordPress/wordpress-develop by gziolo.
4 years ago
#1
- Keywords has-patch has-unit-tests added
#4
@
4 years ago
I'm 100% sure we need the first one. In terms of adding the second one I'm open to discussion since it might duplicate the scope of
register_block_type_args
with the only difference that it contains also the metadata object as an argument passed for processing.
I was thinking about that, I think that both filters make sense. The one that is called just before register_block_type
call is very important from the perspective of Gutenberg as it's the only way to map new values added to block.json
file in the plugin into values that are going to be passed as settings object to register_block_type
call.
#5
@
4 years ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from new to closed
In 49948:
Trac ticket: https://core.trac.wordpress.org/ticket/52138
Related: https://github.com/WordPress/gutenberg/pull/25220, https://core.trac.wordpress.org/ticket/49615
With changes added in https://core.trac.wordpress.org/ticket/49615, it is possible to filter the settings of a block type during its registration with
register_block_type_args
. However, when working https://github.com/WordPress/gutenberg/pull/25220, we discovered that it is still not enough for the case when blocks are registered with block.json metadata. As of today, all core blocks are registered this way and it's impossible to customize the way their styles and scripts are registered or i18n support is handled. The idea here is to add more filters to give more options for plugin authors in the future and account for the needs that Gutenberg has in the constant work to improve the experience around block registration.The attached patch seeks to follow with 2 new hooks:
pre_register_block_type_from_metadata
to filter the content of metadata read from block.jsonpost_register_block_type_from_metadata
to filter the settings object determined from the metadata that is passed to register_block_type callI'm 100% sure we need the first one. In terms of adding the second one, I'm open to discussion since it might duplicate the scope of
register_block_type_args
with the only difference that it contains also the metadata object as an argument passed for processing.