diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index d4481a68a7..8cfa996028 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -237,6 +237,7 @@ class WP_Block { * * @since 6.5.0 * @since 6.6.0 Handle the `__default` attribute for pattern overrides. + * @since 6.7.0 Return any updated bindings metadata in the computed attributes. * * @return array The computed block attributes for the provided block bindings. */ @@ -284,6 +285,14 @@ class WP_Block { : array( 'source' => 'core/pattern-overrides' ); } $bindings = $updated_bindings; + /* + * Update the bindings metadata of the computed attributes. + * This ensures the block receives the expanded __default binding metadata when it renders. + */ + $computed_attributes['metadata'] = array_merge( + $parsed_block['attrs']['metadata'], + array( 'bindings' => $bindings ) + ); } foreach ( $bindings as $attribute_name => $block_binding ) { diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index 6c53ddf994..19ee2c412d 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -334,31 +334,41 @@ HTML; } /** - * Tests if the `__default` attribute is replaced with real attribues for + * Tests if the `__default` attribute is replaced with real attributes for * pattern overrides. * * @ticket 61333 + * @ticket 62069 * * @covers WP_Block::process_block_bindings */ public function test_default_binding_for_pattern_overrides() { - $expected_content = 'This is the content value'; - $block_content = <<
This should not appear
HTML; - $parsed_blocks = parse_blocks( $block_content ); - $block = new WP_Block( $parsed_blocks[0], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) ); - $result = $block->render(); + $expected_content = 'This is the content value'; + $parsed_blocks = parse_blocks( $block_content ); + $block = new WP_Block( $parsed_blocks[0], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) ); + + $result = $block->render(); $this->assertSame( "$expected_content
", trim( $result ), 'The `__default` attribute should be replaced with the real attribute prior to the callback.' ); + + $expected_bindings_metadata = array( + 'content' => array( 'source' => 'core/pattern-overrides' ), + ); + $this->assertSame( + $expected_bindings_metadata, + $block->attributes['metadata']['bindings'], + 'The __default binding should be updated with the individual binding attributes in the block metadata.' + ); } /**