Skip to content

Commit f0344ff

Browse files
committed
In the theme JSON class, linting
In layout.php, move check for global style into gutenberg_render_layout_support_flag
1 parent 1f06fd2 commit f0344ff

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

lib/block-supports/layout.php

+13-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function gutenberg_register_layout_support( $block_type ) {
2828
/**
2929
* Generates the CSS corresponding to the provided layout.
3030
*
31-
* @param string $block_name Name of the current block.
3231
* @param string $selector CSS selector.
3332
* @param array $layout Layout object. The one that is passed has already checked the existence of default block layout.
3433
* @param boolean $has_block_gap_support Whether the theme has support for the block gap.
@@ -37,20 +36,9 @@ function gutenberg_register_layout_support( $block_type ) {
3736
*
3837
* @return string CSS style.
3938
*/
40-
function gutenberg_get_layout_style( $block_name, $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false ) {
39+
function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false ) {
4140
$layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';
4241

43-
// If there is no block-level value for blockGap,
44-
// but a global styles value available for blockGap,
45-
// use the latter.
46-
if ( $has_block_gap_support && empty( $gap_value ) ) {
47-
$block_global_styles = gutenberg_get_global_styles( array( 'blocks', $block_name, 'spacing' ) );
48-
49-
if ( isset( $block_global_styles['blockGap'] ) && ! empty( $block_global_styles['blockGap'] ) ) {
50-
$gap_value = $block_global_styles['blockGap'];
51-
}
52-
}
53-
5442
$style = '';
5543
if ( 'default' === $layout_type ) {
5644
$content_size = isset( $layout['contentSize'] ) ? $layout['contentSize'] : '';
@@ -174,6 +162,17 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
174162

175163
$class_name = wp_unique_id( 'wp-container-' );
176164
$gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
165+
166+
// If there is no block-level value for blockGap,
167+
// but a global styles value available for blockGap,
168+
// use the latter.
169+
if ( empty( $gap_value ) ) {
170+
$spacing_global_styles = gutenberg_get_global_styles( array( 'blocks', $block['blockName'], 'spacing' ) );
171+
if ( isset( $spacing_global_styles['blockGap'] ) && ! empty( $spacing_global_styles['blockGap'] ) ) {
172+
$gap_value = $spacing_global_styles['blockGap'];
173+
}
174+
}
175+
177176
// Skip if gap value contains unsupported characters.
178177
// Regex for CSS value borrowed from `safecss_filter_attr`, and used here
179178
// because we only want to match against the value, not the CSS attribute.
@@ -188,7 +187,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
188187
// If a block's block.json skips serialization for spacing or spacing.blockGap,
189188
// don't apply the user-defined value to the styles.
190189
$should_skip_gap_serialization = gutenberg_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
191-
$style = gutenberg_get_layout_style( $block['blockName'], ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization );
190+
$style = gutenberg_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization );
192191
// This assumes the hook only applies to blocks with a single wrapper.
193192
// I think this is a reasonable limitation for that particular hook.
194193
$content = preg_replace(

lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
107107
protected function get_block_classes( $style_nodes ) {
108108
$block_rules = '';
109109

110-
111110
foreach ( $style_nodes as $metadata ) {
112111
if ( null === $metadata['selector'] ) {
113112
continue;
@@ -176,9 +175,9 @@ protected function get_block_classes( $style_nodes ) {
176175
* )
177176
* ```
178177
*
179-
* @param array $styles Styles to process.
180-
* @param array $settings Theme settings.
181-
* @param array $properties Properties metadata.
178+
* @param array $styles Styles to process.
179+
* @param array $settings Theme settings.
180+
* @param array $properties Properties metadata.
182181
* @param string|null $selector Current selector.
183182
* @return array Returns the modified $declarations.
184183
*/

0 commit comments

Comments
 (0)