[wp-trac] [WordPress Trac] #52138: Editor: Support filtering arguments in block type registration from metadata

WordPress Trac noreply at wordpress.org
Fri Jan 8 16:31:29 UTC 2021


#52138: Editor: Support filtering arguments in block type registration from
metadata
--------------------------------------+---------------------
 Reporter:  gziolo                    |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  5.7
Component:  Editor                    |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------
Description changed by gziolo:

Old description:

> 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 `pre_register_block_type_from_metadata` to filter the content of
> metadata read from `block.json`
> - Named `post_register_block_type_from_metadata` to filter the settings
> object determined from the metadata that is passed to
> `register_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.

New description:

 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 from
 `block.json`
 - Named `block_type_metadata_settings` to filter the settings object
 determined from the metadata that is passed to `register_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.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52138#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list