Changeset 58798
- Timestamp:
- 07/24/2024 10:57:27 AM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r58703 r58798 647 647 if ( isset( $post_content_block_attributes ) ) { 648 648 $editor_settings['postContentAttributes'] = $post_content_block_attributes; 649 } 650 651 // Expose block bindings sources in the editor settings. 652 $registered_block_bindings_sources = get_all_registered_block_bindings_sources(); 653 if ( ! empty( $registered_block_bindings_sources ) ) { 654 // Initialize array. 655 $editor_settings['blockBindingsSources'] = array(); 656 foreach ( $registered_block_bindings_sources as $source_name => $source_properties ) { 657 // Add source with the label to editor settings. 658 $editor_settings['blockBindingsSources'][ $source_name ] = array( 659 'label' => $source_properties->label, 660 ); 661 // Add `usesContext` property if exists. 662 if ( ! empty( $source_properties->uses_context ) ) { 663 $editor_settings['blockBindingsSources'][ $source_name ]['usesContext'] = $source_properties->uses_context; 664 } 665 } 649 666 } 650 667 -
trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php
r58176 r58798 312 312 $expected = new WP_Block_Bindings_Source( $source_two_name, $source_two_properties ); 313 313 $result = $this->registry->get_registered( 'test/source-two' ); 314 $this->registry->unregister( 'test/source-one' ); 315 $this->registry->unregister( 'test/source-two' ); 316 $this->registry->unregister( 'test/source-three' ); 314 317 315 318 $this->assertEquals( … … 381 384 382 385 $new_uses_context = $block_registry->get_registered( 'core/paragraph' )->uses_context; 386 unregister_block_bindings_source( 'test/source-one' ); 387 unregister_block_bindings_source( 'test/source-two' ); 383 388 // Checks that the resulting `uses_context` contains the values from both sources. 384 389 $this->assertContains( 'commonContext', $new_uses_context ); -
trunk/tests/phpunit/tests/blocks/editor.php
r56682 r58798 721 721 ); 722 722 } 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 } 723 757 }
Note: See TracChangeset
for help on using the changeset viewer.