-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Bindings: API to extend the UI to external sources. #71542
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
Conversation
|
Size Change: +737 B (+0.04%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
ace8414 to
f249b89
Compare
c66b68e to
336ed00
Compare
|
Flaky tests detected in bf9f93c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18276654962
|
|
Nice progress on this PR 🔥 |
It is almost ready to review. I only need to update the PR description. Edit: and fix the registration that broke everything 😆 |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Can you provide a more detailed explanation of the API proposed? In, particular What |
We should also pass the attribute to the modal by the way. The value is the 'value' from the 'value' key provided in the data, when the source data is selected. I agree that is not the best way to call it, as it may cause some confusions. I'll change it. Should we pass the entire data element? |
04ee9c5 to
4e818c9
Compare
|
@gziolo I updated the code to use 'item' instead of 'value'. |
I see the updated core sources now use |
|
Ping to @chriszarate. Who did a review on a remote branch that I will address. That way we won't miss him on the props commit. |
I'm still getting an error, although the message is different now:
I'll look into a fix. |
Context wasn't being exposed to the source. I've pushed a fix: 372c976 This removes the error. It's still not working for the "Modal Source" and "Complete Source" -- editing the text in the field in the "Bindings" panel doesn't show any effect. But at least the error is gone 😬 (Wondering a bit what's the purpose of that text field in the first place, and if it's used/required by e2e tests if it's not working 🤔) |
If you remove it, tests break, so yes, seems to be necessary 😆 |
Looks like the error I initially saw is also present on |
|
@cbravobernal, how's the dev note for this PR coming along? |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
Dev Note: Block Bindings improvements.For WordPress users.The Block Bindings user interface has been upgraded to improve how different data sources are displayed in the editor. For WordPress developers.On the serverA new filter, On the editorDevelopers can now register custom sources in the editor UI by adding a ``getFieldsList property to their source registration function. This function must return an array of objects with the following properties:
This is an example that can be tried directly in the console from the Block Editor: wp.blocks.registerBlockBindingsSource({
name: 'state-word/haikus',
label: 'Haikus',
useContext: [ 'postId', 'postType' ],
getValues: ( { bindings } ) => {
// this getValues assumes you're on a paragraph
if ( bindings.content?.args?.haiku === 'one' ) {
return {
content:
'Six point nine arrives,\nBlock bindings bloom like spring flowers,\nEditors rejoice.',
};
}
if ( bindings.content?.args?.haiku === 'two' ) {
return {
content:
'New features unfold,\nPatterns dance with dynamic grace,\nWordPress dreams take flight.',
};
}
if ( bindings.content?.args?.haiku === 'three' ) {
return {
content:
"December's gift shines,\nSix nine brings the future near,\nCreators build more.",
};
}
return {
content: bindings.content,
};
},
getFieldsList() {
return [
{
label: 'First Haiku',
type: 'string',
args: {
haiku: 'one',
},
},
{
label: 'Second Haiku',
type: 'string',
args: {
haiku: 'two',
},
},
{
label: 'Third Haiku',
type: 'string',
args: {
haiku: 'three',
},
},
];
},
} );After executing the code above, when inserting a paragraph, a new UI selector for the Block Binding should be available for the
Props: @ockham and @cbravobernal for implementation. |
|
Nice, thanks for the quick turnaround. Feel free to publish on make/core 🙂 |
|
@cbravobernal It would be wonderful to also have one or two screenshots with the Dev Note. |
|
With WP 6.9 RC1 already released, please go ahead and publish the Dev Note on make.wordpress.org/core 🙏 |
|
Thanks, Carlos! I marked is a fully done ✅ |


What?
This PR introduces a Block Bindings EditorUI API that allows third-party developers to extend the block bindings UI with their own sources.
Why?
The existing block bindings system lacked for an extensible UI: No way for plugins to customize the bindings interface
How
Dropdown Mode:
Modal Mode:
The attributes validation is made following this docs: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#type-validation
String values can also contain : https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#format
getFieldsListbackwards compatible? (Already done)For follow-up PRs:
isCheckedsolution. Do not make it key dependant.Screenshot
testing.mp4