From e2c70a167e15028b5753f3ddc49b397d7e4e236f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Thu, 6 Aug 2020 17:09:30 +0200 Subject: [PATCH 1/2] Take editor features data from blocks as well --- lib/global-styles.php | 23 +++++++++++-------- .../components/use-editor-feature/index.js | 12 ++++++---- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 852ce5ef3dd37..0b9413dc4608b 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -596,22 +596,27 @@ function gutenberg_experimental_global_styles_enqueue_assets() { * @return array Default features config for the editor. */ function gutenberg_experimental_global_styles_get_editor_features( $config ) { - if ( - empty( $config['global']['features'] ) || - ! is_array( $config['global']['features'] ) - ) { - $config['global']['features'] = array(); + $features = array(); + foreach ( array_keys( $config ) as $context ) { + if ( + empty( $config[ $context ]['features'] ) || + ! is_array( $config[ $context ]['features']) + ) { + $features[ $context ] = array(); + } else { + $features[ $context ] = $config[ $context ]['features']; + } } // Deprecated theme supports. if ( get_theme_support( 'disable-custom-colors' ) ) { - if ( ! isset( $config['global']['features']['color'] ) ) { - $config['global']['features']['color'] = array(); + if ( ! isset( $features['global']['color'] ) ) { + $features['global']['color'] = array(); } - $config['global']['features']['color']['custom'] = false; + $features['global']['color']['custom'] = false; } - return $config['global']['features']; + return $features; } /** diff --git a/packages/block-editor/src/components/use-editor-feature/index.js b/packages/block-editor/src/components/use-editor-feature/index.js index efda6385ece3c..e1ed370ec0160 100644 --- a/packages/block-editor/src/components/use-editor-feature/index.js +++ b/packages/block-editor/src/components/use-editor-feature/index.js @@ -38,8 +38,6 @@ export default function useEditorFeature( featurePath ) { const setting = useSelect( ( select ) => { - const path = `__experimentalFeatures.${ featurePath }`; - // 1 - Use deprecated settings, if available. const settings = select( 'core/block-editor' ).getSettings(); const deprecatedSettingsValue = deprecatedFlags[ featurePath ] @@ -49,8 +47,14 @@ export default function useEditorFeature( featurePath ) { return deprecatedSettingsValue; } - // 2 - Use global __experimentalFeatures otherwise. - return get( settings, path ); + // 2 - Use __experimental features otherwise. + // We cascade to the global value if the block one is not available. + // + // TODO: make it work for blocks that define multiple selectors + // such as core/heading or core/post-title. + const globalPath = `__experimentalFeatures.global.${ featurePath }`; + const blockPath = `__experimentalFeatures.${ blockName }.${ featurePath }`; + return get( settings, blockPath ) ?? get( settings, globalPath ); }, [ blockName, featurePath ] ); From b9cb92a2cd1db85cc7ce20cc35608e295bce6890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 31 Aug 2020 14:06:35 +0200 Subject: [PATCH 2/2] Make linter happy --- lib/global-styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 0b9413dc4608b..99c7fb91846ae 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -600,7 +600,7 @@ function gutenberg_experimental_global_styles_get_editor_features( $config ) { foreach ( array_keys( $config ) as $context ) { if ( empty( $config[ $context ]['features'] ) || - ! is_array( $config[ $context ]['features']) + ! is_array( $config[ $context ]['features'] ) ) { $features[ $context ] = array(); } else {