-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block API: Add new utility to register block types from metadata in PHP #20794
Conversation
Size Change: 0 B Total Size: 864 kB ℹ️ View Unchanged
|
8d0dfa0
to
e0e9de0
Compare
e0e9de0
to
73c9144
Compare
73c9144
to
3345144
Compare
I made PHPUnit tests pass, and all jobs on Travis. I think it's ready for the final check. |
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.
Some general thoughts which occur to me, mostly a brain dump and none of which are particularly blocking:
- I'm wondering how this relates or is expected to interoperate with other plugin filesystem functions. Looking at ones like
plugin_dir_path
, which often receive__FILE__
of the plugin file, then it's up to the plugin author to concatenate that to whichever file they're targeting. This feels a bit different in that it absorbs most of that responsibility, and assumes that the metadata will always be found atblock.json
. - If and where we should document this sooner than later, or at least how best we can seek feedback in the early stages of the availability of this function.
Yeah, that was the earlier idea with a separate function to calculate the path. But it is quite straightforward to do, so opted for not adding a separate helper function. Using either
Was thinking that is expected, like having |
My first idea was to omit the documentation part until we reach WordPress 5.5 release cycle to avoid all the confusion for those who browse https://developer.wordpress.org/block-editor/ and can't use this new block registration utility with WordPress core. We also miss support for two features proposed in Block Registration RFC: I think it might be a good idea to add a section in this RFC document as a follow-up (plus refresh the document in general) that would describe how this is going to work moving forward. If you agree I'm happy to open a follow-up PR.
I don't think we strictly require |
Not necessarily, no. It just struck me as rather opinionated in how we're expecting a plugin of blocks to be structured. As an example, perhaps one might feel compelled to have a folder of blocks instead of a folder of folders of blocks (i.e. |
Let's proceed here and work on documentation in a follow-up task. I will also open a new issue in trac with a proposal to include it in WordPress core. Thank you for all feedback shared. |
I opened #21501 where I document this new method in RFC document. Next step, propose it to WordPress core. |
…` metadata file Backports changes added to Gutenberg in: - WordPress/gutenberg#20794 - WordPress/gutenberg#22519 `register_block_type_from_metadata` function is going to be used to register all blocks on the server using `block.json` metadata files. Props ocean90, azaozz, aduth, mcsf, jorgefilipecosta, spacedmonkey, nosolosw, swissspidy and noahtallen. Fixes #50263. git-svn-id: https://develop.svn.wordpress.org/trunk@48141 602fd350-edb4-49c9-b593-d223f7449a82
…` metadata file Backports changes added to Gutenberg in: - WordPress/gutenberg#20794 - WordPress/gutenberg#22519 `register_block_type_from_metadata` function is going to be used to register all blocks on the server using `block.json` metadata files. Props ocean90, azaozz, aduth, mcsf, jorgefilipecosta, spacedmonkey, nosolosw, swissspidy and noahtallen. Fixes #50263. git-svn-id: https://develop.svn.wordpress.org/trunk@48141 602fd350-edb4-49c9-b593-d223f7449a82
…` metadata file Backports changes added to Gutenberg in: - WordPress/gutenberg#20794 - WordPress/gutenberg#22519 `register_block_type_from_metadata` function is going to be used to register all blocks on the server using `block.json` metadata files. Props ocean90, azaozz, aduth, mcsf, jorgefilipecosta, spacedmonkey, nosolosw, swissspidy and noahtallen. Fixes #50263. Built from https://develop.svn.wordpress.org/trunk@48141 git-svn-id: http://core.svn.wordpress.org/trunk@47910 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…` metadata file Backports changes added to Gutenberg in: - WordPress/gutenberg#20794 - WordPress/gutenberg#22519 `register_block_type_from_metadata` function is going to be used to register all blocks on the server using `block.json` metadata files. Props ocean90, azaozz, aduth, mcsf, jorgefilipecosta, spacedmonkey, nosolosw, swissspidy and noahtallen. Fixes #50263. Built from https://develop.svn.wordpress.org/trunk@48141 git-svn-id: https://core.svn.wordpress.org/trunk@47910 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…` metadata file Backports changes added to Gutenberg in: - WordPress/gutenberg#20794 - WordPress/gutenberg#22519 `register_block_type_from_metadata` function is going to be used to register all blocks on the server using `block.json` metadata files. Props ocean90, azaozz, aduth, mcsf, jorgefilipecosta, spacedmonkey, nosolosw, swissspidy and noahtallen. Fixes #50263. git-svn-id: https://develop.svn.wordpress.org/trunk@48141 602fd350-edb4-49c9-b593-d223f7449a82
Description
Follow up for #19786 and #20717 where we started using
block.json
file in PHP to register block types.This PR tries to simplify the process by removing code duplication for the same tasks that need happen for every block.
API is based on my previous discussion with @azaozz. I hightlighed the most important parts below:
API proposed
Example
How has this been tested?
npm run test-php && npm run test-unit-php-multisite
npm run test-e2e
I also manually tested that the experimental Edit Site still works and all blocks are registered on the server.
Types of changes
New API method introduced and core blocks are refactored to use it.
Checklist: