diff --git a/lib/class-wp-theme-json-resolver.php b/lib/class-wp-theme-json-resolver.php index 31ecb553a2ccd..7b3b7f4426c97 100644 --- a/lib/class-wp-theme-json-resolver.php +++ b/lib/class-wp-theme-json-resolver.php @@ -195,13 +195,13 @@ private static function translate( $theme_json, $domain = 'default' ) { /* * We need to process the paths that include '*' separately. * One example of such a path would be: - * [ 'settings', '*', 'color', 'palette' ] + * [ 'settings', 'blocks', '*', 'color', 'palette' ] */ $nodes_to_iterate = array_keys( $path, '*', true ); if ( ! empty( $nodes_to_iterate ) ) { /* * At the moment, we only need to support one '*' in the path, so take it directly. - * - base will be [ 'settings' ] + * - base will be [ 'settings', 'blocks' ] * - data will be [ 'color', 'palette' ] */ $base_path = array_slice( $path, 0, $nodes_to_iterate[0] ); @@ -213,7 +213,7 @@ private static function translate( $theme_json, $domain = 'default' ) { continue; } - // Whole path will be [ 'settings', 'core/paragraph', 'color', 'palette' ]. + // Whole path will be [ 'settings', 'blocks', 'core/paragraph', 'color', 'palette' ]. $whole_path = array_merge( $base_path, array( $node_name ), $data_path ); $translated_array = self::translate_theme_json_chunk( $array_to_translate, $key, $context, $domain ); gutenberg_experimental_set( $theme_json, $whole_path, $translated_array ); diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index da910ca84747a..ac8858e56694f 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -1,7 +1,7 @@ { + "version": 1, "settings": { - "defaults": { - "color": { + "color": { "palette": [ { "name": "Black", @@ -129,8 +129,8 @@ "custom": true, "link": false, "customGradient": true - }, - "typography": { + }, + "typography": { "dropCap": true, "customFontSize": true, "customLineHeight": false, @@ -165,14 +165,13 @@ "size": "42px" } ] - }, - "spacing": { - "customPadding": false, - "units": [ "px", "em", "rem", "vh", "vw" ] - }, - "border": { - "customRadius": false - } + }, + "spacing": { + "customPadding": false, + "units": [ "px", "em", "rem", "vh", "vw" ] + }, + "border": { + "customRadius": false } } } diff --git a/lib/experimental-i18n-theme.json b/lib/experimental-i18n-theme.json index 94889f733a331..6ef549e8af7a4 100644 --- a/lib/experimental-i18n-theme.json +++ b/lib/experimental-i18n-theme.json @@ -1,7 +1,6 @@ { "settings": { - "*": { - "typography": { + "typography": { "fontSizes": [ { "name": "Font size name" @@ -32,8 +31,8 @@ "name": "Text decoration name" } ] - }, - "color": { + }, + "color": { "palette": [ { "name": "Color name" @@ -44,6 +43,53 @@ "name": "Gradient name" } ] + }, + "blocks": { + "*": { + "typography": { + "fontSizes": [ + { + "name": "Font size name" + } + ], + "fontStyles": [ + { + "name": "Font style name" + } + ], + "fontWeights": [ + { + "name": "Font weight name" + } + ], + "fontFamilies": [ + { + "name": "Font family name" + } + ], + "textTransforms": [ + { + "name": "Text transform name" + } + ], + "textDecorations": [ + { + "name": "Text decoration name" + } + ] + }, + "color": { + "palette": [ + { + "name": "Color name" + } + ], + "gradients": [ + { + "name": "Gradient name" + } + ] + } } } }, diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php index 66c6d946c4721..8ec9022b2d047 100644 --- a/phpunit/class-wp-theme-json-resolver-test.php +++ b/phpunit/class-wp-theme-json-resolver-test.php @@ -45,42 +45,82 @@ function test_fields_are_extracted() { $expected = array( array( - 'path' => array( 'settings', '*', 'typography', 'fontSizes' ), + 'path' => array( 'settings', 'typography', 'fontSizes' ), 'key' => 'name', 'context' => 'Font size name', ), array( - 'path' => array( 'settings', '*', 'typography', 'fontStyles' ), + 'path' => array( 'settings', 'typography', 'fontStyles' ), 'key' => 'name', 'context' => 'Font style name', ), array( - 'path' => array( 'settings', '*', 'typography', 'fontWeights' ), + 'path' => array( 'settings', 'typography', 'fontWeights' ), 'key' => 'name', 'context' => 'Font weight name', ), array( - 'path' => array( 'settings', '*', 'typography', 'fontFamilies' ), + 'path' => array( 'settings', 'typography', 'fontFamilies' ), 'key' => 'name', 'context' => 'Font family name', ), array( - 'path' => array( 'settings', '*', 'typography', 'textTransforms' ), + 'path' => array( 'settings', 'typography', 'textTransforms' ), 'key' => 'name', 'context' => 'Text transform name', ), array( - 'path' => array( 'settings', '*', 'typography', 'textDecorations' ), + 'path' => array( 'settings', 'typography', 'textDecorations' ), 'key' => 'name', 'context' => 'Text decoration name', ), array( - 'path' => array( 'settings', '*', 'color', 'palette' ), + 'path' => array( 'settings', 'color', 'palette' ), 'key' => 'name', 'context' => 'Color name', ), array( - 'path' => array( 'settings', '*', 'color', 'gradients' ), + 'path' => array( 'settings', 'color', 'gradients' ), + 'key' => 'name', + 'context' => 'Gradient name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'typography', 'fontSizes' ), + 'key' => 'name', + 'context' => 'Font size name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'typography', 'fontStyles' ), + 'key' => 'name', + 'context' => 'Font style name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'typography', 'fontWeights' ), + 'key' => 'name', + 'context' => 'Font weight name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'typography', 'fontFamilies' ), + 'key' => 'name', + 'context' => 'Font family name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'typography', 'textTransforms' ), + 'key' => 'name', + 'context' => 'Text transform name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'typography', 'textDecorations' ), + 'key' => 'name', + 'context' => 'Text decoration name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'color', 'palette' ), + 'key' => 'name', + 'context' => 'Color name', + ), + array( + 'path' => array( 'settings', 'blocks', '*', 'color', 'gradients' ), 'key' => 'name', 'context' => 'Gradient name', ), @@ -107,22 +147,37 @@ function test_translations_are_applied() { $this->assertSame( wp_get_theme()->get( 'TextDomain' ), 'fse' ); $this->assertSame( - $actual->get_settings()['root']['color'], array( - 'palette' => array( - array( - 'slug' => 'light', - 'name' => 'Jasny', - 'color' => '#f5f7f9', + 'color' => array( + 'palette' => array( + array( + 'slug' => 'light', + 'name' => 'Jasny', + 'color' => '#f5f7f9', + ), + array( + 'slug' => 'dark', + 'name' => 'Ciemny', + 'color' => '#000', + ), ), - array( - 'slug' => 'dark', - 'name' => 'Ciemny', - 'color' => '#000', + 'custom' => false, + ), + 'blocks' => array( + 'core/paragraph' => array( + 'color' => array( + 'palette' => array( + array( + 'slug' => 'light', + 'name' => 'Jasny', + 'color' => '#f5f7f9', + ), + ), + ), ), ), - 'custom' => false, - ) + ), + $actual->get_settings() ); $this->assertSame( $actual->get_custom_templates(), diff --git a/phpunit/data/themedir1/fse/experimental-theme.json b/phpunit/data/themedir1/fse/experimental-theme.json index 3cfe4accc5beb..bda2c7646305c 100644 --- a/phpunit/data/themedir1/fse/experimental-theme.json +++ b/phpunit/data/themedir1/fse/experimental-theme.json @@ -1,20 +1,32 @@ { + "version": 1, "settings": { - "root": { - "color": { - "palette": [ - { - "slug": "light", - "name": "Light", - "color": "#f5f7f9" - }, - { - "slug": "dark", - "name": "Dark", - "color": "#000" - } - ], - "custom": false + "color": { + "palette": [ + { + "slug": "light", + "name": "Light", + "color": "#f5f7f9" + }, + { + "slug": "dark", + "name": "Dark", + "color": "#000" + } + ], + "custom": false + }, + "blocks": { + "core/paragraph": { + "color": { + "palette": [ + { + "slug": "light", + "name": "Light", + "color": "#f5f7f9" + } + ] + } } } },