Skip to content

Commit 1fc81a3

Browse files
Merge pull request #2138 from WordPress/fix/2137-default-column
Fix: Moved `column_count` context from `column` block to `columns` block to ensure it is available to ancestor blocks
2 parents 84002b1 + 0573247 commit 1fc81a3

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

plugins/auto-sizes/includes/improve-calculate-sizes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $blo
306306
'core/image' => array( 'max_alignment', 'container_relative_width' ),
307307
'core/post-featured-image' => array( 'max_alignment', 'container_relative_width' ),
308308
'core/group' => array( 'max_alignment' ),
309-
'core/columns' => array( 'max_alignment', 'container_relative_width' ),
310-
'core/column' => array( 'max_alignment', 'column_count' ),
309+
'core/columns' => array( 'max_alignment', 'column_count', 'container_relative_width' ),
310+
'core/column' => array( 'max_alignment' ),
311311
);
312312

313313
if ( isset( $block_specific_context[ $block_type->name ] ) ) {

plugins/auto-sizes/tests/test-improve-calculate-sizes.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,63 @@ public static function data_image_block_with_parent_columns_and_its_parent_group
12721272
);
12731273
}
12741274

1275+
/**
1276+
* Test that the image block in a two-column layout renders the correct sizes attribute.
1277+
*
1278+
* @cover ::auto_sizes_filter_image_tag
1279+
*/
1280+
public function test_image_block_in_two_column_layout_renders_correct_sizes_attribute(): void {
1281+
// Skip test for WordPress versions below 6.8.
1282+
if ( version_compare( get_bloginfo( 'version' ), '6.8', '<' ) ) {
1283+
$this->markTestSkipped( 'This test requires WordPress 6.8 or higher.' );
1284+
}
1285+
1286+
$block_content = '<!-- wp:columns -->
1287+
<div class="wp-block-columns"><!-- wp:column -->
1288+
<div class="wp-block-column">
1289+
' . $this->get_image_block_markup( self::$image_id, 'large' ) . '
1290+
</div>
1291+
<!-- /wp:column -->
1292+
<!-- wp:column -->
1293+
<div class="wp-block-column"></div>
1294+
<!-- /wp:column --></div>
1295+
<!-- /wp:columns -->';
1296+
1297+
$result = apply_filters( 'the_content', $block_content );
1298+
1299+
$this->assertStringContainsString( 'sizes="(max-width: 310px) 100vw, 310px" ', $result );
1300+
}
1301+
1302+
/**
1303+
* Test that the image block in a three-column layout renders the correct sizes attribute.
1304+
*
1305+
* @cover ::auto_sizes_filter_image_tag
1306+
*/
1307+
public function test_image_block_in_three_column_layout_renders_correct_sizes_attribute(): void {
1308+
// Skip test for WordPress versions below 6.8.
1309+
if ( version_compare( get_bloginfo( 'version' ), '6.8', '<' ) ) {
1310+
$this->markTestSkipped( 'This test requires WordPress 6.8 or higher.' );
1311+
}
1312+
1313+
$block_content = '<!-- wp:columns -->
1314+
<div class="wp-block-columns"><!-- wp:column -->
1315+
<div class="wp-block-column">
1316+
' . $this->get_image_block_markup( self::$image_id, 'large' ) . '
1317+
</div>
1318+
<!-- /wp:column -->
1319+
<!-- wp:column -->
1320+
<div class="wp-block-column"></div>
1321+
<!-- /wp:column -->
1322+
<!-- wp:column -->
1323+
<div class="wp-block-column"></div>
1324+
<!-- /wp:column --></div>
1325+
<!-- /wp:columns -->';
1326+
1327+
$result = apply_filters( 'the_content', $block_content );
1328+
1329+
$this->assertStringContainsString( 'sizes="(max-width: 206px) 100vw, 206px" ', $result );
1330+
}
1331+
12751332
/**
12761333
* Verifies that the post featured image block does not render when no featured image is set for the post.
12771334
*/

0 commit comments

Comments
 (0)