Changeset 56960
- Timestamp:
- 10/17/2023 03:46:44 PM (14 months ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r56943 r56960 548 548 } 549 549 550 $before_block_visitor = ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ? '_inject_theme_attribute_in_template_part_block' : null;550 $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; 551 551 $after_block_visitor = null; 552 552 $hooked_blocks = get_hooked_blocks(); … … 555 555 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); 556 556 } 557 if ( null !== $before_block_visitor || null !== $after_block_visitor ) { 558 $blocks = parse_blocks( $template_content ); 559 $template_content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 560 } 561 $template->content = $template_content; 557 $blocks = parse_blocks( $template_content ); 558 $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 562 559 563 560 return $template; -
trunk/src/wp-includes/blocks.php
r56896 r56960 780 780 */ 781 781 return function ( &$block, $parent_block = null, $prev = null ) use ( $hooked_blocks, $context ) { 782 if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { 783 _inject_theme_attribute_in_template_part_block( $block ); 784 } 782 _inject_theme_attribute_in_template_part_block( $block ); 785 783 786 784 $markup = ''; -
trunk/src/wp-includes/class-wp-block-patterns-registry.php
r56896 r56960 166 166 $content = $pattern['content']; 167 167 168 $before_block_visitor = ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ? '_inject_theme_attribute_in_template_part_block' : null;168 $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; 169 169 $after_block_visitor = null; 170 170 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { … … 172 172 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $pattern ); 173 173 } 174 if ( null !== $before_block_visitor || null !== $after_block_visitor ) { 175 $blocks = parse_blocks( $content ); 176 $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 177 } 174 $blocks = parse_blocks( $content ); 175 $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 178 176 179 177 return $content; -
trunk/tests/phpunit/tests/block-template-utils.php
r56896 r56960 163 163 164 164 /** 165 * @ticket 59325 166 * 167 * @covers ::_build_block_template_result_from_file 168 * 169 * @dataProvider data_build_block_template_result_from_file_injects_theme_attribute 170 * 171 * @param string $filename The template's filename. 172 * @param string $expected The expected block markup. 173 */ 174 public function test_build_block_template_result_from_file_injects_theme_attribute( $filename, $expected ) { 175 $template = _build_block_template_result_from_file( 176 array( 177 'slug' => 'single', 178 'path' => DIR_TESTDATA . "/templates/$filename", 179 ), 180 'wp_template' 181 ); 182 $this->assertSame( $expected, $template->content ); 183 } 184 185 /** 186 * Data provider. 187 * 188 * @return array[] 189 */ 190 public function data_build_block_template_result_from_file_injects_theme_attribute() { 191 $theme = 'block-theme'; 192 return array( 193 'a template with a template part block' => array( 194 'filename' => 'template-with-template-part.html', 195 'expected' => sprintf( 196 '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->', 197 $theme 198 ), 199 ), 200 'a template with a template part block nested inside another block' => array( 201 'filename' => 'template-with-nested-template-part.html', 202 'expected' => sprintf( 203 '<!-- wp:group --> 204 <!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /--> 205 <!-- /wp:group -->', 206 $theme 207 ), 208 ), 209 'a template with a template part block with an existing theme attribute' => array( 210 'filename' => 'template-with-template-part-with-existing-theme-attribute.html', 211 'expected' => '<!-- wp:template-part {"slug":"header","theme":"fake-theme","align":"full","tagName":"header","className":"site-header"} /-->', 212 ), 213 'a template with no template part block' => array( 214 'filename' => 'template.html', 215 'expected' => '<!-- wp:paragraph --> 216 <p>Just a paragraph</p> 217 <!-- /wp:paragraph -->', 218 ), 219 ); 220 } 221 222 /** 165 223 * @ticket 59338 166 224 * -
trunk/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php
r56896 r56960 318 318 319 319 /** 320 * Should insert a theme attribute into Template Part blocks in registered patterns. 321 * 322 * @ticket 59583 323 * 324 * @covers WP_Block_Patterns_Registry::register 325 * @covers WP_Block_Patterns_Registry::get_all_registered 326 */ 327 public function test_get_all_registered_includes_theme_attribute() { 328 $test_pattern = array( 329 'title' => 'Test Pattern', 330 'content' => '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->', 331 ); 332 $this->registry->register( 'test/pattern', $test_pattern ); 333 334 $expected = sprintf( 335 '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->', 336 get_stylesheet() 337 ); 338 $patterns = $this->registry->get_all_registered(); 339 $this->assertSame( $expected, $patterns[0]['content'] ); 340 } 341 342 /** 320 343 * Should insert hooked blocks into registered patterns. 321 344 * … … 370 393 371 394 /** 395 * Should insert a theme attribute into Template Part blocks in registered patterns. 396 * 397 * @ticket 59583 398 * 399 * @covers WP_Block_Patterns_Registry::register 400 * @covers WP_Block_Patterns_Registry::get_registered 401 */ 402 public function test_get_registered_includes_theme_attribute() { 403 $test_pattern = array( 404 'title' => 'Test Pattern', 405 'content' => '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->', 406 ); 407 $this->registry->register( 'test/pattern', $test_pattern ); 408 409 $expected = sprintf( 410 '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->', 411 get_stylesheet() 412 ); 413 $pattern = $this->registry->get_registered( 'test/pattern' ); 414 $this->assertSame( $expected, $pattern['content'] ); 415 } 416 417 /** 372 418 * Should insert hooked blocks into registered patterns. 373 419 *
Note: See TracChangeset
for help on using the changeset viewer.