Changeset 57246
- Timestamp:
- 01/08/2024 06:12:00 AM (9 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/layout.php
r57077 r57246 639 639 */ 640 640 $container_class = wp_unique_prefixed_id( 641 'wp-container-' . sanitize_title( $block['blockName'] ) . '- layout-'641 'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-' 642 642 ); 643 643 … … 884 884 } 885 885 886 $replace_regex = sprintf( 886 /* 887 * This filter runs after the layout classnames have been added to the block, so they 888 * have to be removed from the outer wrapper and then added to the inner. 889 */ 890 $layout_classes = array(); 891 $processor = new WP_HTML_Tag_Processor( $block_content ); 892 893 if ( $processor->next_tag( array( 'class_name' => 'wp-block-group' ) ) ) { 894 foreach ( $processor->class_list() as $class_name ) { 895 if ( str_contains( $class_name, 'is-layout-' ) ) { 896 $layout_classes[] = $class_name; 897 $processor->remove_class( $class_name ); 898 } 899 } 900 } 901 902 $content_without_layout_classes = $processor->get_updated_html(); 903 $replace_regex = sprintf( 887 904 '/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms', 888 905 preg_quote( $tag_name, '/' ) 889 906 ); 890 $updated_content = preg_replace_callback(907 $updated_content = preg_replace_callback( 891 908 $replace_regex, 892 909 static function ( $matches ) { 893 910 return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3]; 894 911 }, 895 $ block_content912 $content_without_layout_classes 896 913 ); 914 915 // Add layout classes to inner wrapper. 916 if ( ! empty( $layout_classes ) ) { 917 $processor = new WP_HTML_Tag_Processor( $updated_content ); 918 if ( $processor->next_tag( array( 'class_name' => 'wp-block-group__inner-container' ) ) ) { 919 foreach ( $layout_classes as $class_name ) { 920 $processor->add_class( $class_name ); 921 } 922 } 923 $updated_content = $processor->get_updated_html(); 924 } 897 925 return $updated_content; 898 926 } -
trunk/tests/phpunit/tests/block-supports/layout.php
r55956 r57246 253 253 ); 254 254 } 255 256 /** 257 * Check that wp_restore_group_inner_container() restores the legacy inner container on the Group block. 258 * 259 * @ticket 60130 260 * 261 * @covers ::wp_restore_group_inner_container 262 * 263 * @dataProvider data_restore_group_inner_container 264 * 265 * @param array $args Dataset to test. 266 * @param string $expected_output The expected output. 267 */ 268 public function test_restore_group_inner_container( $args, $expected_output ) { 269 $actual_output = wp_restore_group_inner_container( $args['block_content'], $args['block'] ); 270 $this->assertEquals( $expected_output, $actual_output ); 271 } 272 273 /** 274 * Data provider for test_restore_group_inner_container. 275 * 276 * @return array 277 */ 278 public function data_restore_group_inner_container() { 279 return array( 280 'group block with existing inner container' => array( 281 'args' => array( 282 'block_content' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>', 283 'block' => array( 284 'blockName' => 'core/group', 285 'attrs' => array( 286 'layout' => array( 287 'type' => 'default', 288 ), 289 ), 290 'innerBlocks' => array(), 291 'innerHTML' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>', 292 'innerContent' => array( 293 '<div class="wp-block-group"><div class="wp-block-group__inner-container">', 294 ' ', 295 ' </div></div>', 296 ), 297 ), 298 ), 299 'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>', 300 ), 301 'group block with no existing inner container' => array( 302 'args' => array( 303 'block_content' => '<div class="wp-block-group"></div>', 304 'block' => array( 305 'blockName' => 'core/group', 306 'attrs' => array( 307 'layout' => array( 308 'type' => 'default', 309 ), 310 ), 311 'innerBlocks' => array(), 312 'innerHTML' => '<div class="wp-block-group"></div>', 313 'innerContent' => array( 314 '<div class="wp-block-group">', 315 ' ', 316 ' </div>', 317 ), 318 ), 319 ), 320 'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>', 321 ), 322 'group block with layout classnames' => array( 323 'args' => array( 324 'block_content' => '<div class="wp-block-group is-layout-constrained wp-block-group-is-layout-constrained"></div>', 325 'block' => array( 326 'blockName' => 'core/group', 327 'attrs' => array( 328 'layout' => array( 329 'type' => 'default', 330 ), 331 ), 332 'innerBlocks' => array(), 333 'innerHTML' => '<div class="wp-block-group"></div>', 334 'innerContent' => array( 335 '<div class="wp-block-group">', 336 ' ', 337 ' </div>', 338 ), 339 ), 340 ), 341 'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained"></div></div>', 342 ), 343 ); 344 } 255 345 }
Note: See TracChangeset
for help on using the changeset viewer.