Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #62705


Ignore:
Timestamp:
12/17/2024 09:22:00 PM (3 months ago)
Author:
cbravobernal
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #62705

    • Property Keywords has-patch added
  • Ticket #62705 – Description

    initial v2  
    1 Needs Gutenberg PR to work:
    2 https://github.com/WordPress/gutenberg/pull/67802/
     1''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].''
     2Trac ticket: https://core.trac.wordpress.org/ticket/62705
     3
     4## What?
     5I'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.
     6
     7This registration:
     8
     9{{{
     10#!php
     11register_block_bindings_source(
     12                        'bbe/now-date',
     13                        array(
     14                                'label'              => __( 'Current date', 'custom-bindings' ),
     15                                'get_value_callback' => function ( array $source_args, $block_instance ) {
     16                                        return gmdate( $source_args['key'] );
     17                                },
     18                                'fields'             =>
     19                                        array(
     20                                                'Y-m-d H:i:s' => array(
     21                                                        'type'  => 'string',
     22                                                        'value' => 'Y-m-d H:i:s',
     23                                                ),
     24                                                'D'           => array(
     25                                                        'type'  => 'string',
     26                                                        'value' => 'D',
     27                                                ),
     28                                        ),
     29                        )
     30                );
     31}}}
     32
     33
     34will return:
     35
     36[[Image(https://github.com/user-attachments/assets/0e08f37c-829a-46c9-880c-511453bc20d4)]]
     37
     38We 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.
     39[[Image(https://github.com/user-attachments/assets/71246745-a02f-432c-b6b0-69157bdccec4)]]
     40
     41
     42[[Image(https://github.com/user-attachments/assets/60f7934a-e772-457f-8be7-f9ca32fd1a1e)]]