Editor: Fix ref values within block style variations.

Fixes an issue where block style variations that use `ref` values to reference styles elsewhere in theme.json weren't working.

Retrieves reference values when generating styles for block style variations. How? When retrieving variation data, to generate styles from, also retrieve any referenced values.

Reviewed by audrasjb.
Merges [58691] to the 6.6 branch.

Props aaronrobertshaw, andrewserong, ramonopoly.
Fixes #61589.
Built from https://develop.svn.wordpress.org/branches/6.6@58699


git-svn-id: http://core.svn.wordpress.org/branches/6.6@58101 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2024-07-09 16:08:15 +00:00
parent df6f9bdc6a
commit 98b5022652
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.6-RC2-58698';
$wp_version = '6.6-RC2-58699';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.