From ee9a630a710105ef05432bba4f2bdbb6cc33657b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 10 Jun 2020 12:49:33 +0200 Subject: [PATCH 1/2] Make link color control opt-in --- lib/client-assets.php | 15 +++++++++++++++ packages/block-editor/src/hooks/color.js | 5 +++-- packages/editor/src/components/provider/index.js | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 3bf11c6510ca5b..e56bec615f6495 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -703,6 +703,21 @@ function gutenberg_extend_settings_custom_spacing( $settings ) { } add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_spacing' ); + +/** + * Extends block editor settings to determine whether to use custom spacing controls. + * Currently experimental. + * + * @param array $settings Default editor settings. + * + * @return array Filtered editor settings. + */ +function gutenberg_extend_settings_link_color( $settings ) { + $settings['__experimentalEnableLinkColor'] = get_theme_support( 'experimental-link-color' ); + return $settings; +} +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_link_color' ); + /* * Register default patterns if not registered in Core already. */ diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index 0c527226798924..135ed6f86764be 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -180,9 +180,10 @@ const getLinkColorFromAttributeValue = ( colors, value ) => { */ export function ColorEdit( props ) { const { name: blockName, attributes } = props; - const { colors, gradients } = useSelect( ( select ) => { + const { colors, gradients, __experimentalEnableLinkColor } = useSelect( ( select ) => { return select( 'core/block-editor' ).getSettings(); }, [] ); + // Shouldn't be needed but right now the ColorGradientsPanel // can trigger both onChangeColor and onChangeBackground // synchronously causing our two callbacks to override changes @@ -310,7 +311,7 @@ export function ColorEdit( props ) { ? onChangeGradient : undefined, }, - ...( hasLinkColorSupport( blockName ) + ...( __experimentalEnableLinkColor && hasLinkColorSupport( blockName ) ? [ { label: __( 'Link Color' ), diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index a0b03cd64bb3b8..57cfb4af84da4d 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -118,6 +118,7 @@ class EditorProvider extends Component { '__experimentalDisableCustomLineHeight', '__experimentalEnableCustomSpacing', '__experimentalEnableLegacyWidgetBlock', + '__experimentalEnableLinkColor', '__experimentalEnableFullSiteEditing', '__experimentalEnableFullSiteEditingDemo', '__experimentalFeatures', From 434e083a230c6b790c9454e178894e2e2cd7abe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 10 Jun 2020 12:50:07 +0200 Subject: [PATCH 2/2] Commit prettier suggestions --- packages/block-editor/src/hooks/color.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index 135ed6f86764be..12837b4322cef0 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -180,9 +180,12 @@ const getLinkColorFromAttributeValue = ( colors, value ) => { */ export function ColorEdit( props ) { const { name: blockName, attributes } = props; - const { colors, gradients, __experimentalEnableLinkColor } = useSelect( ( select ) => { - return select( 'core/block-editor' ).getSettings(); - }, [] ); + const { colors, gradients, __experimentalEnableLinkColor } = useSelect( + ( select ) => { + return select( 'core/block-editor' ).getSettings(); + }, + [] + ); // Shouldn't be needed but right now the ColorGradientsPanel // can trigger both onChangeColor and onChangeBackground @@ -311,7 +314,8 @@ export function ColorEdit( props ) { ? onChangeGradient : undefined, }, - ...( __experimentalEnableLinkColor && hasLinkColorSupport( blockName ) + ...( __experimentalEnableLinkColor && + hasLinkColorSupport( blockName ) ? [ { label: __( 'Link Color' ),