Make WordPress Core


Ignore:
Timestamp:
07/24/2024 10:57:27 AM (2 years ago)
Author:
cbravobernal
Message:

Block Bindings: Adds sources in the editor settings to consume them in the client

Adds a new property blockBindingsSources to the editor settings to expose the block bindings sources registered in the server.

Props santosguillamot, cbravobernal, gziolo, artemiosans.
Fixes #61641.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/editor.php

    r56682 r58798  
    721721                );
    722722        }
     723
     724        /**
     725         * @ticket 61641
     726         */
     727        public function test_get_block_editor_settings_block_bindings_sources() {
     728                $block_editor_context = new WP_Block_Editor_Context();
     729                register_block_bindings_source(
     730                        'test/source-one',
     731                        array(
     732                                'label'              => 'Source One',
     733                                'get_value_callback' => function () {},
     734                                'uses_context'       => array( 'postId' ),
     735                        )
     736                );
     737                register_block_bindings_source(
     738                        'test/source-two',
     739                        array(
     740                                'label'              => 'Source Two',
     741                                'get_value_callback' => function () {},
     742                        )
     743                );
     744                $settings        = get_block_editor_settings( array(), $block_editor_context );
     745                $exposed_sources = $settings['blockBindingsSources'];
     746                unregister_block_bindings_source( 'test/source-one' );
     747                unregister_block_bindings_source( 'test/source-two' );
     748                // It is expected to have 4 sources: the 2 registered sources in the test, and the 2 core sources.
     749                $this->assertCount( 4, $exposed_sources );
     750                $source_one = $exposed_sources['test/source-one'];
     751                $this->assertSame( 'Source One', $source_one['label'] );
     752                $this->assertSameSets( array( 'postId' ), $source_one['usesContext'] );
     753                $source_two = $exposed_sources['test/source-two'];
     754                $this->assertSame( 'Source Two', $source_two['label'] );
     755                $this->assertArrayNotHasKey( 'usesContext', $source_two );
     756        }
    723757}
Note: See TracChangeset for help on using the changeset viewer.