Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,6 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
return $style;
}

/**
* Generates the utility classnames for the given blocks layout attributes.
* This method was primarily added to reintroduce classnames that were removed
* in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719), rather
* than providing an extensive list of all possible layout classes. The plan is to
* have the style engine generate a more extensive list of utility classnames which
* will then replace this method.
*
* @param array $block_attributes Array of block attributes.
*
* @return array Array of CSS classname strings.
*/
function gutenberg_get_layout_classes( $block_attributes ) {
$class_names = array();

if ( empty( $block_attributes['layout'] ) ) {
return $class_names;
}

if ( ! empty( $block_attributes['layout']['orientation'] ) ) {
$class_names[] = 'is-' . sanitize_title( $block_attributes['layout']['orientation'] );
}

if ( ! empty( $block_attributes['layout']['justifyContent'] ) ) {
$class_names[] = 'is-content-justification-' . sanitize_title( $block_attributes['layout']['justifyContent'] );
}

if ( ! empty( $block_attributes['layout']['flexWrap'] ) && 'nowrap' === $block_attributes['layout']['flexWrap'] ) {
$class_names[] = 'is-nowrap';
}

return $class_names;
}

/**
* Renders the layout config to the block wrapper.
*
Expand Down Expand Up @@ -206,10 +172,26 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$used_layout = $default_layout;
}

$class_names = array();
$container_class = wp_unique_id( 'wp-container-' );
$class_names = gutenberg_get_layout_classes( $block['attrs'] );
$class_names[] = $container_class;

// The following section was added to reintroduce a small set of layout classnames that were
// removed in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719). It is
// not intended to provide an extended set of classes to match all block layout attributes
// here.
if ( ! empty( $block['attrs']['layout']['orientation'] ) ) {
$class_names[] = 'is-' . sanitize_title( $block['attrs']['layout']['orientation'] );
}

if ( ! empty( $block['attrs']['layout']['justifyContent'] ) ) {
$class_names[] = 'is-content-justification-' . sanitize_title( $block['attrs']['layout']['justifyContent'] );
}

if ( ! empty( $block['attrs']['layout']['flexWrap'] ) && 'nowrap' === $block['attrs']['layout']['flexWrap'] ) {
$class_names[] = 'is-nowrap';
}

$gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
// Skip if gap value contains unsupported characters.
// Regex for CSS value borrowed from `safecss_filter_attr`, and used here
Expand Down