[wp-trac] [WordPress Trac] #62705: Block Bindings: Try fields registration on server.
WordPress Trac
noreply at wordpress.org
Tue Dec 17 21:22:00 UTC 2024
#62705: Block Bindings: Try fields registration on server.
--------------------------+------------------------------
Reporter: cbravobernal | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------------------
Description changed by cbravobernal:
Old description:
> Needs Gutenberg PR to work:
> https://github.com/WordPress/gutenberg/pull/67802/
New description:
''This ticket was mentioned in [https://github.com/WordPress/wordpress-
develop/pull/7987 PR #7987] on [https://github.com/WordPress/wordpress-
develop/ WordPress/wordpress-develop] by
[https://profiles.wordpress.org/cbravobernal/ @cbravobernal].''
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:
{{{
#!php
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' => 'Y-m-d
H:i:s',
),
'D' => array(
'type' =>
'string',
'value' => 'D',
),
),
)
);
}}}
will return:
[[Image(https://github.com/user-attachments/assets/0e08f37c-829a-46c9
-880c-511453bc20d4)]]
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.
[[Image(https://github.com/user-attachments/assets/71246745-a02f-432c-
b6b0-69157bdccec4)]]
[[Image(https://github.com/user-attachments/assets/60f7934a-e772-457f-
8be7-f9ca32fd1a1e)]]
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62705#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list