Section Styles: Fix ref values within block style variations.

Fixes #61589.
Fixes https://github.com/WordPress/wordpress-develop/pull/6989.
See https://github.com/WordPress/gutenberg/pull/63172.

Props aaronrobertshaw, andrewserong, ramonopoly.


Built from https://develop.svn.wordpress.org/trunk@58691


git-svn-id: http://core.svn.wordpress.org/trunk@58093 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ellatrix 2024-07-09 10:24:19 +00:00
parent 5e060bc838
commit c56593dfe1
2 changed files with 43 additions and 1 deletions

View File

@ -40,6 +40,42 @@ function wp_get_block_style_variation_name_from_class( $class_string ) {
return $matches[1] ?? null;
}
/**
* Recursively resolves any `ref` values within a block style variation's data.
*
* @since 6.6.0
* @access private
*
* @param array $variation_data Reference to the variation data being processed.
* @param array $theme_json Theme.json data to retrieve referenced values from.
*/
function wp_resolve_block_style_variation_ref_values( &$variation_data, $theme_json ) {
foreach ( $variation_data as $key => &$value ) {
// Only need to potentially process arrays.
if ( is_array( $value ) ) {
// If ref value is set, attempt to find its matching value and update it.
if ( array_key_exists( 'ref', $value ) ) {
// Clean up any invalid ref value.
if ( empty( $value['ref'] ) || ! is_string( $value['ref'] ) ) {
unset( $variation_data[ $key ] );
}
$value_path = explode( '.', $value['ref'] ?? '' );
$ref_value = _wp_array_get( $theme_json, $value_path );
// Only update the current value if the referenced path matched a value.
if ( null === $ref_value ) {
unset( $variation_data[ $key ] );
} else {
$value = $ref_value;
}
} else {
// Recursively look for ref instances.
wp_resolve_block_style_variation_ref_values( $value, $theme_json );
}
}
}
}
/**
* Render the block style variation's styles.
*
@ -82,6 +118,12 @@ function wp_render_block_style_variation_support_styles( $parsed_block ) {
return $parsed_block;
}
/*
* Recursively resolve any ref values with the appropriate value within the
* theme_json data.
*/
wp_resolve_block_style_variation_ref_values( $variation_data, $theme_json );
$variation_instance = wp_create_block_style_variation_instance_name( $parsed_block, $variation );
$class_name = "is-style-$variation_instance";
$updated_class_name = $parsed_block['attrs']['className'] . " $class_name";

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-58690';
$wp_version = '6.7-alpha-58691';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.