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] 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 ] );