-
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 Bindings: Prepare the ground to define fieldsList on the server. #67802
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: -20 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Flaky tests detected in d67ccf7. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12261868808
|
What I don't like of this approach is that only the key is needed to render the frontend. The value could be anything, and that anything would be shown on the frontend if you don't tweak it with register_block_bindings_source(
'bbe/now-date',
array(
'label' => __( 'Current date', 'custom-bindings' ),
'get_value_callback' => function ( array $source_args, $block_instance ) {
return gmdate( $source_args['key'] );
},
'fields' =>
array(
'Y-m-d H:i:s' => array(
'type' => 'string',
'value' => 'i don\'t use it',
),
'D' => array(
'type' => 'string',
'value' => 'i don\'t use it',
),
),
)
); Would still render this on the editor: <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"bbe/now-date","args":{"key":"Y-m-d H:i:s"}}}}} -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"bbe/now-date","args":{"key":"Y-m-d H:i:s"}}}}} -->
<p></p>
<!-- /wp:paragraph --> |
How can it be tested? I see the following warning printed when using this branch and the example code:
|
I left a comment in the WordPress Trac ticket that covers my initial thoughts. It looks like everything is going in the right direction in this PR. We need to settle first on how the API shapes on the server to see what changes are required for the client. |
You need to have both this PR for the editor and the wordpress-develop PR in order to work as expected. It should appear something like this on the editor with this registration: register_block_bindings_source(
'bbe/now-date',
array(
'label' => __( 'Current dates', 'custom-bindings' ),
'get_value_callback' => function ( array $source_args, $block_instance ) {
switch ( $source_args['key'] ) {
case 'y_m_d':
return gmdate( 'Y M D' );
case 'y_m_d_h_i_s':
return gmdate( 'Y M D h i s' );
default:
return gmdate( 'Y M D h i s' );
}
},
'args' => array(
'y_m_d' => array(
'type' => 'string',
'label' => __( 'Y M D', 'custom-bindings' ),
'value' => gmdate( 'Y M D' ),
),
'y_m_d_h_i_s' => array(
'type' => 'string',
'label' => __( 'Y M D h i s', 'custom-bindings' ),
'value' => gmdate( 'Y M D h i s' ),
),
),
),
); |
Trac ticket: https://core.trac.wordpress.org/ticket/62705
What?
I'm experimenting if it is possible to add sources to the UI just by defining them on the server side. It will need a PR in Gutenberg to be landed.
This registration:
will return:
We are using keys as the source arguments to decide the format. It's an approach I'm not 100% comfortable with. We may need to update the JS API.