-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 bindings: Expose sources in the editor settings to consume them in the client #7020
Conversation
Trac Ticket MissingThis pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
I’m wondering if we can update an existing unit test to validate the setting is correctly propagated to the editor Maybe something similar to wordpress-develop/tests/phpunit/tests/blocks/editor.php Lines 468 to 473 in dea027e
|
I have just added this new unit test to check that the registered sources are properly added to the editor settings: link. |
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.
Looks good to me 👍
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'm very excited about the work that exposes the sources from the server, as we will have a better information to share with users about sources, and an improved handling for the necessary block context.
@@ -77,6 +77,9 @@ public function test_get_all_registered() { | |||
); | |||
|
|||
$registered = get_all_registered_block_bindings_sources(); | |||
unregister_block_bindings_source( 'test/source-one' ); |
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.
These lines are redundant as there is automated cleanup included in the tear_down
lifecycle method:
wordpress-develop/tests/phpunit/tests/block-bindings/register.php
Lines 38 to 43 in a18de61
public function tear_down() { | |
foreach ( get_all_registered_block_bindings_sources() as $source_name => $source_properties ) { | |
if ( str_starts_with( $source_name, 'test/' ) ) { | |
unregister_block_bindings_source( $source_name ); | |
} | |
} |
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.
That makes sense 🙂 And it explains why they weren't failing before. I made this change as part of this commit.
@@ -269,6 +269,9 @@ public function test_get_all_registered() { | |||
); | |||
|
|||
$registered = $this->registry->get_all_registered(); | |||
$this->registry->unregister( 'test/source-one' ); |
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 one is more nuanced, but also redundant. There is a new instance of the registry created for every test using the lifecycle method set_up
:
$this->registry = new WP_Block_Bindings_Registry(); |
So, the instance with registered custom sources doesn't persist between tests.
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.
Makes sense as well 🙂 I made this change as part of this commit.
Completed with my first commit to Core in https://core.trac.wordpress.org/changeset/58798 |
Thanks for committing this early in the 6.7 cycle ❤️ |
Originally explored in this other pull request: #6456
What?
It adds a new property to the editor settings to expose the block bindings sources registered in the server. This allows to reuse some of its properties like
label
anduses_context
without having to replicate that in JavaScript.There is a related pull request in Gutenberg, where these settings are being consumed.
Why?
It makes some block bindings editor functionalities work by default, improving the user experience, and it simplifies how sources are registered in the client.
How?
Add a new property including all the registered sources while the editor settings are being initialized.
Trac ticket: https://core.trac.wordpress.org/ticket/61641
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.