Skip to content

Commit

Permalink
Post Template: Output number of columns as classname for backwards co…
Browse files Browse the repository at this point in the history
…mpatibility (#51358)

* Grid Layout: Output number of columns as classname for backwards compatibility

* Refactor to only apply to the post template block
  • Loading branch information
andrewserong authored Jun 9, 2023
1 parent 291a195 commit 238d9a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ export default function PostTemplateEdit( {
);

const blockProps = useBlockProps( {
className: classnames( __unstableLayoutClassNames ),
className: classnames( __unstableLayoutClassNames, {
[ `columns-${ columnCount }` ]:
layoutType === 'grid' && columnCount, // Ensure column count is flagged via classname for backwards compatibility.
} ),
} );

if ( ! posts ) {
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function render_block_core_post_template( $attributes, $content, $block ) {
$classnames .= ' has-link-color';
}

// Ensure backwards compatibility by flagging the number of columns via classname when using grid layout.
if ( isset( $attributes['layout']['type'] ) && 'grid' === $attributes['layout']['type'] && ! empty( $attributes['layout']['columnCount'] ) ) {
$classnames .= ' ' . sanitize_title( 'columns-' . $attributes['layout']['columnCount'] );
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classnames ) ) );

$content = '';
Expand Down

0 comments on commit 238d9a9

Please sign in to comment.