mirror of
git://develop.git.wordpress.org/
synced 2025-04-26 07:02:13 +02:00
Block bindings: Ensure block receives __default bindings when render.
Fixes an issue with the image block when using pattern overrides, where the image block with overrides enabled was not outputting all the expected image attributes. Ensures that the `process_block_bindings` method returns any updates to the block's binding metadata along with other computed attributes. Props talldanwp, cbravobernal, santosguillamot, mukesh27, gziolo. Fixes #62069. git-svn-id: https://develop.svn.wordpress.org/trunk@59095 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8dd9ca0402
commit
d9cb6e7e9d
@ -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 ) {
|
||||
|
@ -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 = <<<HTML
|
||||
<!-- wp:paragraph {"metadata":{"bindings":{"__default":{"source":"core/pattern-overrides"}},"name":"Test"}} -->
|
||||
<p>This should not appear</p>
|
||||
<!-- /wp:paragraph -->
|
||||
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(
|
||||
"<p>$expected_content</p>",
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user