Skip to content

Commit

Permalink
In the theme JSON class, linting
Browse files Browse the repository at this point in the history
In layout.php, move check for global style into gutenberg_render_layout_support_flag
  • Loading branch information
ramonjd committed Apr 27, 2022
1 parent 7a21fa3 commit e4d87c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function gutenberg_register_layout_support( $block_type ) {
/**
* Generates the CSS corresponding to the provided layout.
*
* @param string $block_name Name of the current block.
* @param string $selector CSS selector.
* @param array $layout Layout object. The one that is passed has already checked the existence of default block layout.
* @param boolean $has_block_gap_support Whether the theme has support for the block gap.
Expand All @@ -37,20 +36,9 @@ function gutenberg_register_layout_support( $block_type ) {
*
* @return string CSS style.
*/
function gutenberg_get_layout_style( $block_name, $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false ) {
function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false ) {
$layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';

// If there is no block-level value for blockGap,
// but a global styles value available for blockGap,
// use the latter.
if ( $has_block_gap_support && empty( $gap_value ) ) {
$block_global_styles = gutenberg_get_global_styles( array( 'blocks', $block_name, 'spacing' ) );

if ( isset( $block_global_styles['blockGap'] ) && ! empty( $block_global_styles['blockGap'] ) ) {
$gap_value = $block_global_styles['blockGap'];
}
}

$style = '';
if ( 'default' === $layout_type ) {
$content_size = isset( $layout['contentSize'] ) ? $layout['contentSize'] : '';
Expand Down Expand Up @@ -186,6 +174,17 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {

$class_name = wp_unique_id( 'wp-container-' );
$gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );

// If there is no block-level value for blockGap,
// but a global styles value available for blockGap,
// use the latter.
if ( empty( $gap_value ) ) {
$spacing_global_styles = gutenberg_get_global_styles( array( 'blocks', $block['blockName'], 'spacing' ) );
if ( isset( $spacing_global_styles['blockGap'] ) && ! empty( $spacing_global_styles['blockGap'] ) ) {
$gap_value = $spacing_global_styles['blockGap'];
}
}

// Skip if gap value contains unsupported characters.
// Regex for CSS value borrowed from `safecss_filter_attr`, and used here
// because we only want to match against the value, not the CSS attribute.
Expand All @@ -200,7 +199,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
// If a block's block.json skips serialization for spacing or spacing.blockGap,
// don't apply the user-defined value to the styles.
$should_skip_gap_serialization = gutenberg_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
$style = gutenberg_get_layout_style( $block['blockName'], ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization );
$style = gutenberg_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization );
// This assumes the hook only applies to blocks with a single wrapper.
// I think this is a reasonable limitation for that particular hook.
$content = preg_replace(
Expand Down
6 changes: 3 additions & 3 deletions lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ protected function get_block_classes( $style_nodes ) {
* )
* ```
*
* @param array $styles Styles to process.
* @param array $settings Theme settings.
* @param array $properties Properties metadata.
* @param array $styles Styles to process.
* @param array $settings Theme settings.
* @param array $properties Properties metadata.
* @param string|null $selector Current selector.
* @return array Returns the modified $declarations.
*/
Expand Down

0 comments on commit e4d87c5

Please sign in to comment.