Changeset 59095
- Timestamp:
- 09/26/2024 02:49:13 PM (7 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block.php
r59080 r59095 238 238 * @since 6.5.0 239 239 * @since 6.6.0 Handle the `__default` attribute for pattern overrides. 240 * @since 6.7.0 Return any updated bindings metadata in the computed attributes. 240 241 * 241 242 * @return array The computed block attributes for the provided block bindings. … … 285 286 } 286 287 $bindings = $updated_bindings; 288 /* 289 * Update the bindings metadata of the computed attributes. 290 * This ensures the block receives the expanded __default binding metadata when it renders. 291 */ 292 $computed_attributes['metadata'] = array_merge( 293 $parsed_block['attrs']['metadata'], 294 array( 'bindings' => $bindings ) 295 ); 287 296 } 288 297 -
trunk/tests/phpunit/tests/block-bindings/render.php
r59080 r59095 335 335 336 336 /** 337 * Tests if the `__default` attribute is replaced with real attribu es for337 * Tests if the `__default` attribute is replaced with real attributes for 338 338 * pattern overrides. 339 339 * 340 340 * @ticket 61333 341 * @ticket 62069 341 342 * 342 343 * @covers WP_Block::process_block_bindings 343 344 */ 344 345 public function test_default_binding_for_pattern_overrides() { 345 $expected_content = 'This is the content value';346 347 346 $block_content = <<<HTML 348 347 <!-- wp:paragraph {"metadata":{"bindings":{"__default":{"source":"core/pattern-overrides"}},"name":"Test"}} --> … … 351 350 HTML; 352 351 353 $parsed_blocks = parse_blocks( $block_content ); 354 $block = new WP_Block( $parsed_blocks[0], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) ); 355 $result = $block->render(); 352 $expected_content = 'This is the content value'; 353 $parsed_blocks = parse_blocks( $block_content ); 354 $block = new WP_Block( $parsed_blocks[0], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) ); 355 356 $result = $block->render(); 356 357 357 358 $this->assertSame( … … 359 360 trim( $result ), 360 361 'The `__default` attribute should be replaced with the real attribute prior to the callback.' 362 ); 363 364 $expected_bindings_metadata = array( 365 'content' => array( 'source' => 'core/pattern-overrides' ), 366 ); 367 $this->assertSame( 368 $expected_bindings_metadata, 369 $block->attributes['metadata']['bindings'], 370 'The __default binding should be updated with the individual binding attributes in the block metadata.' 361 371 ); 362 372 }
Note: See TracChangeset
for help on using the changeset viewer.