diff --git a/packages/block-library/src/social-link/edit.js b/packages/block-library/src/social-link/edit.js index 6e916eff5a5229..bc0919669f3f77 100644 --- a/packages/block-library/src/social-link/edit.js +++ b/packages/block-library/src/social-link/edit.js @@ -25,7 +25,7 @@ import { keyboardReturn } from '@wordpress/icons'; /** * Internal dependencies */ -import { getIconBySite, getNameBySite } from './social-list'; +import { useServiceIcon, useServiceName } from './social-list'; const SocialLinkURLPopover = ( { url, @@ -77,8 +77,8 @@ const SocialLinkEdit = ( { } ); const ref = useRef(); - const IconComponent = getIconBySite( service ); - const socialLinkName = getNameBySite( service ); + const IconComponent = useServiceIcon( service ); + const socialLinkName = useServiceName( service ); const blockProps = useBlockProps( { className: classes, style: { diff --git a/packages/block-library/src/social-link/edit.native.js b/packages/block-library/src/social-link/edit.native.js index 06bf104661819b..3994f09174201a 100644 --- a/packages/block-library/src/social-link/edit.native.js +++ b/packages/block-library/src/social-link/edit.native.js @@ -18,12 +18,12 @@ import { } from '@wordpress/components'; import { compose, usePreferredColorSchemeStyle } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; -import { link, Icon } from '@wordpress/icons'; +import { link } from '@wordpress/icons'; import { withSelect } from '@wordpress/data'; /** * Internal dependencies */ -import { getIconBySite, getNameBySite } from './social-list'; +import { useServiceIcon, useServiceName } from './social-list'; import styles from './editor.scss'; const ANIMATION_DELAY = 300; @@ -65,8 +65,8 @@ const SocialLinkEdit = ( { const animatedValue = useRef( new Animated.Value( 0 ) ).current; - const IconComponent = getIconBySite( service )(); - const socialLinkName = getNameBySite( service ); + const IconComponent = useServiceIcon( service ); + const socialLinkName = useServiceName( service ); // When new social icon is added link sheet is opened automatically useEffect( () => { @@ -192,11 +192,7 @@ const SocialLinkEdit = ( { - + diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index d0c353ad9358c0..2ec6e9220e84c4 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -278,6 +278,8 @@ function block_core_social_link_services( $service = '', $field = '' ) { ), ); + $services_data = apply_filters( 'block_editor_social_link_services', $services_data ); + if ( ! empty( $service ) && ! empty( $field ) && isset( $services_data[ $service ] ) diff --git a/packages/block-library/src/social-link/social-list.js b/packages/block-library/src/social-link/social-list.js index 9ac527dccd0d39..be281a27be51ad 100644 --- a/packages/block-library/src/social-link/social-list.js +++ b/packages/block-library/src/social-link/social-list.js @@ -7,11 +7,12 @@ import { find } from 'lodash'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; +import { useSelect } from '@wordpress/data'; +import { store as blocksStore } from '@wordpress/blocks'; /** * Internal dependencies */ -import variations from './variations'; import { ChainIcon } from './icons'; /** @@ -21,7 +22,11 @@ import { ChainIcon } from './icons'; * * @return {WPComponent} Icon component for social service. */ -export const getIconBySite = ( name ) => { +export const useServiceIcon = ( name ) => { + const variations = useSelect( ( select ) => { + const { getBlockVariations } = select( blocksStore ); + return getBlockVariations( 'core/social-link', 'block' ); + } ); const variation = find( variations, { name } ); return variation ? variation.icon : ChainIcon; }; @@ -33,7 +38,11 @@ export const getIconBySite = ( name ) => { * * @return {string} Display name for social service */ -export const getNameBySite = ( name ) => { +export const useServiceName = ( name ) => { + const variations = useSelect( ( select ) => { + const { getBlockVariations } = select( blocksStore ); + return getBlockVariations( 'core/social-link', 'block' ); + } ); const variation = find( variations, { name } ); return variation ? variation.title : __( 'Social Icon' ); };