From d88a3700a85672ab6bd3f7a42eb385a4a9add0ec Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Tue, 3 Sep 2019 17:55:15 +1000 Subject: [PATCH 01/25] Introduce a filter to overrider Document label in Document Settings Header. --- .../src/components/sidebar/settings-header/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 04132d6f2664e..93b7498ed8b49 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -3,6 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { withDispatch } from '@wordpress/data'; +import { applyFilters } from '@wordpress/hooks'; /** * Internal dependencies @@ -11,11 +12,12 @@ import SidebarHeader from '../sidebar-header'; const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName } ) => { const blockLabel = __( 'Block' ); + const documentLabel = applyFilters( 'editor.sidebar.settingsHeader.documentLabel', __( 'Document' ) ); const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. - [ __( 'Document (selected)' ), 'is-active' ] : + [ `${ documentLabel } ${ __( '(selected)' ) }`, 'is-active' ] : // translators: ARIA label for the Document sidebar tab, not selected. - [ __( 'Document' ), '' ]; + [ documentLabel, '' ]; const [ blockAriaLabel, blockActiveClass ] = sidebarName === 'edit-post/block' ? // translators: ARIA label for the Settings Sidebar tab, selected. @@ -35,9 +37,9 @@ const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName onClick={ openDocumentSettings } className={ `edit-post-sidebar__panel-tab ${ documentActiveClass }` } aria-label={ documentAriaLabel } - data-label={ __( 'Document' ) } + data-label={ documentLabel } > - { __( 'Document' ) } + { documentLabel }
  • From 0de2bb44cf0f7182c92ad25eaddc9fb372155ff7 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Wed, 4 Sep 2019 10:57:22 +1000 Subject: [PATCH 02/25] Move the translator comment for ARIA label. --- .../edit-post/src/components/sidebar/settings-header/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 93b7498ed8b49..1699ed72d01e1 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -12,11 +12,11 @@ import SidebarHeader from '../sidebar-header'; const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName } ) => { const blockLabel = __( 'Block' ); + // translators: ARIA label for the Document sidebar tab, not selected. const documentLabel = applyFilters( 'editor.sidebar.settingsHeader.documentLabel', __( 'Document' ) ); const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. [ `${ documentLabel } ${ __( '(selected)' ) }`, 'is-active' ] : - // translators: ARIA label for the Document sidebar tab, not selected. [ documentLabel, '' ]; const [ blockAriaLabel, blockActiveClass ] = sidebarName === 'edit-post/block' ? From c2d4dc0c188fb86b89527d4688a716500adedd95 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Wed, 4 Sep 2019 11:03:46 +1000 Subject: [PATCH 03/25] Replace string concatenation with sprintf. --- .../src/components/sidebar/settings-header/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 1699ed72d01e1..cdcd5d338ef7a 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { withDispatch } from '@wordpress/data'; import { applyFilters } from '@wordpress/hooks'; @@ -15,8 +15,8 @@ const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName // translators: ARIA label for the Document sidebar tab, not selected. const documentLabel = applyFilters( 'editor.sidebar.settingsHeader.documentLabel', __( 'Document' ) ); const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? - // translators: ARIA label for the Document sidebar tab, selected. - [ `${ documentLabel } ${ __( '(selected)' ) }`, 'is-active' ] : + // translators: 1: ARIA label for the Document sidebar tab, selected. + [ sprintf( __( '%1$s (selected)' ), documentLabel ), 'is-active' ] : [ documentLabel, '' ]; const [ blockAriaLabel, blockActiveClass ] = sidebarName === 'edit-post/block' ? From 8652601fef7b9022d2fcbf243ed0baf2da50620d Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sun, 5 Apr 2020 21:27:07 +1000 Subject: [PATCH 04/25] Introduce useFilters React hook. --- .../src/higher-order/use-filters/index.js | 40 +++++++++++++++++++ packages/components/src/index.js | 1 + .../sidebar/settings-header/index.js | 10 ++--- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 packages/components/src/higher-order/use-filters/index.js diff --git a/packages/components/src/higher-order/use-filters/index.js b/packages/components/src/higher-order/use-filters/index.js new file mode 100644 index 0000000000000..4b23aed1c9a48 --- /dev/null +++ b/packages/components/src/higher-order/use-filters/index.js @@ -0,0 +1,40 @@ +/** + * WordPress dependencies + */ +import { useEffect, useCallback, useState } from '@wordpress/element'; +import { addAction, applyFilters, removeAction } from '@wordpress/hooks'; + +const useFilters = ( hookName, originalValue, ...args ) => { + const namespace = 'core/use-filter/' + hookName; + + const [ filteredValue, setFilteredValue ] = useState( + applyFilters( hookName, originalValue, ...args ) + ); + + const forceUpdate = useCallback( () => { + setFilteredValue( applyFilters( hookName, originalValue, ...args ) ); + }, [ filteredValue, setFilteredValue, hookName, originalValue, args ] ); + + const onHooksUpdated = useCallback( + ( updatedHookName ) => { + if ( updatedHookName === hookName ) { + forceUpdate(); + } + }, + [ hookName, forceUpdate ] + ); + + useEffect( () => { + addAction( 'hookRemoved', namespace, onHooksUpdated ); + addAction( 'hookAdded', namespace, onHooksUpdated ); + + return () => { + removeAction( 'hookRemoved', namespace ); + removeAction( 'hookAdded', namespace ); + }; + }, [ filteredValue, onHooksUpdated, namespace ] ); + + return filteredValue; +}; + +export default useFilters; diff --git a/packages/components/src/index.js b/packages/components/src/index.js index 75ddd43d7daf7..37fb5f2f474ce 100644 --- a/packages/components/src/index.js +++ b/packages/components/src/index.js @@ -105,6 +105,7 @@ export { } from './slot-fill'; // Higher-Order Components +export { default as useFilters } from './higher-order/use-filters'; export { default as navigateRegions } from './higher-order/navigate-regions'; export { default as withConstrainedTabbing } from './higher-order/with-constrained-tabbing'; export { default as withFallbackStyles } from './higher-order/with-fallback-styles'; diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 1cbb9d40a9687..7e406c35692e2 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,10 +1,9 @@ /** * WordPress dependencies */ -import { Button } from '@wordpress/components'; +import { Button, useFilters } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { withDispatch } from '@wordpress/data'; -import { applyFilters } from '@wordpress/hooks'; const SettingsHeader = ( { openDocumentSettings, @@ -12,11 +11,12 @@ const SettingsHeader = ( { sidebarName, } ) => { const blockLabel = __( 'Block' ); - // translators: ARIA label for the Document sidebar tab, not selected. - const documentLabel = applyFilters( - 'editor.sidebar.settingsHeader.documentLabel', + const documentLabel = useFilters( + 'edit-post.sidebar.settings-header.document-label', + // translators: ARIA label for the Document sidebar tab, not selected. __( 'Document' ) ); + const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. From d92d8ee9d7f036667e512461920eb1fde66a4295 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sat, 18 Apr 2020 00:50:38 +1000 Subject: [PATCH 05/25] Prefer template literal over string concatenation. --- packages/components/src/higher-order/use-filters/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/higher-order/use-filters/index.js b/packages/components/src/higher-order/use-filters/index.js index 4b23aed1c9a48..e87a1ad3df5f1 100644 --- a/packages/components/src/higher-order/use-filters/index.js +++ b/packages/components/src/higher-order/use-filters/index.js @@ -5,7 +5,7 @@ import { useEffect, useCallback, useState } from '@wordpress/element'; import { addAction, applyFilters, removeAction } from '@wordpress/hooks'; const useFilters = ( hookName, originalValue, ...args ) => { - const namespace = 'core/use-filter/' + hookName; + const namespace = `core/use-filter/${ hookName }`; const [ filteredValue, setFilteredValue ] = useState( applyFilters( hookName, originalValue, ...args ) From 8338a940b9d51d2e65b79e39473789e5a0933abc Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sun, 10 May 2020 17:09:13 +1000 Subject: [PATCH 06/25] Use PHP filter instead of JS filter. --- lib/client-assets.php | 16 ++++++++ .../src/higher-order/use-filters/index.js | 40 ------------------- packages/components/src/index.js | 1 - .../sidebar/settings-header/index.js | 14 +++---- .../editor/src/components/provider/index.js | 1 + 5 files changed, 24 insertions(+), 48 deletions(-) delete mode 100644 packages/components/src/higher-order/use-filters/index.js diff --git a/lib/client-assets.php b/lib/client-assets.php index 885ba362710dd..e9e6f377b54b9 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -693,3 +693,19 @@ function gutenberg_extend_settings_custom_units( $settings ) { register_block_pattern( 'core/its-time', gutenberg_load_block_pattern( 'its-time' ) ); register_block_pattern( 'core/testimonials', gutenberg_load_block_pattern( 'testimonials' ) ); } + +/** + * Extends block editor settings to include UI labels to be shown for elements. + * + * Currently experimental. + * + * @param array $settings Default editor settings. + * @return array Modified editor settings. + */ +function gutenberg_extend_settings_ui_labels( $settings ) { + $settings['__experimentalLabels'] = array( + 'document' => __( 'Document', 'gutenberg' ), + ); + return $settings; +} +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_ui_labels' ); diff --git a/packages/components/src/higher-order/use-filters/index.js b/packages/components/src/higher-order/use-filters/index.js deleted file mode 100644 index e87a1ad3df5f1..0000000000000 --- a/packages/components/src/higher-order/use-filters/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * WordPress dependencies - */ -import { useEffect, useCallback, useState } from '@wordpress/element'; -import { addAction, applyFilters, removeAction } from '@wordpress/hooks'; - -const useFilters = ( hookName, originalValue, ...args ) => { - const namespace = `core/use-filter/${ hookName }`; - - const [ filteredValue, setFilteredValue ] = useState( - applyFilters( hookName, originalValue, ...args ) - ); - - const forceUpdate = useCallback( () => { - setFilteredValue( applyFilters( hookName, originalValue, ...args ) ); - }, [ filteredValue, setFilteredValue, hookName, originalValue, args ] ); - - const onHooksUpdated = useCallback( - ( updatedHookName ) => { - if ( updatedHookName === hookName ) { - forceUpdate(); - } - }, - [ hookName, forceUpdate ] - ); - - useEffect( () => { - addAction( 'hookRemoved', namespace, onHooksUpdated ); - addAction( 'hookAdded', namespace, onHooksUpdated ); - - return () => { - removeAction( 'hookRemoved', namespace ); - removeAction( 'hookAdded', namespace ); - }; - }, [ filteredValue, onHooksUpdated, namespace ] ); - - return filteredValue; -}; - -export default useFilters; diff --git a/packages/components/src/index.js b/packages/components/src/index.js index b56bee906849e..ca4df08a9e4a3 100644 --- a/packages/components/src/index.js +++ b/packages/components/src/index.js @@ -108,7 +108,6 @@ export { } from './slot-fill'; // Higher-Order Components -export { default as useFilters } from './higher-order/use-filters'; export { default as navigateRegions } from './higher-order/navigate-regions'; export { default as withConstrainedTabbing } from './higher-order/with-constrained-tabbing'; export { default as withFallbackStyles } from './higher-order/with-fallback-styles'; diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 7e406c35692e2..83418ac080112 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,21 +1,20 @@ /** * WordPress dependencies */ -import { Button, useFilters } from '@wordpress/components'; +import { Button } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, useSelect } from '@wordpress/data'; const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName, } ) => { - const blockLabel = __( 'Block' ); - const documentLabel = useFilters( - 'edit-post.sidebar.settings-header.document-label', + const documentLabel = useSelect( ( select ) => { + const settings = select( 'core/block-editor' ).getSettings(); // translators: ARIA label for the Document sidebar tab, not selected. - __( 'Document' ) - ); + return settings?.__experimentalLabels?.document ?? __( 'Document' ); + } ); const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' @@ -24,6 +23,7 @@ const SettingsHeader = ( { : // translators: ARIA label for the Document sidebar tab, not selected. [ documentLabel, '' ]; + const blockLabel = __( 'Block' ); const [ blockAriaLabel, blockActiveClass ] = sidebarName === 'edit-post/block' ? // translators: ARIA label for the Settings Sidebar tab, selected. diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 2868759b6b0d9..ae07c4a6db470 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -121,6 +121,7 @@ class EditorProvider extends Component { '__experimentalEnableFullSiteEditingDemo', '__experimentalGlobalStylesUserEntityId', '__experimentalGlobalStylesBase', + '__experimentalLabels', '__experimentalPreferredStyleVariations', 'alignWide', 'allowedBlockTypes', From ce395867afee9494d4025130a6fd9fd48b1b4b50 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Fri, 15 May 2020 20:52:32 +1000 Subject: [PATCH 07/25] Use Post Type label for Custom Post Types. Keep using Document for Posts and Pages. --- lib/client-assets.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index e9e6f377b54b9..b887aada36031 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -703,9 +703,17 @@ function gutenberg_extend_settings_custom_units( $settings ) { * @return array Modified editor settings. */ function gutenberg_extend_settings_ui_labels( $settings ) { + $post_type = get_post_type(); + $post_type_object = get_post_type_object( $post_type ); + + $document_label = in_array( $post_type, array( 'post', 'page' ), true ) ? + __( 'Document', 'gutenberg' ) : + $post_type_object->labels->singular_name; + $settings['__experimentalLabels'] = array( - 'document' => __( 'Document', 'gutenberg' ), + 'document' => $document_label, ); + return $settings; } add_filter( 'block_editor_settings', 'gutenberg_extend_settings_ui_labels' ); From 2b4f1e9b0262b0c588e98b7c4ea7f48c66b60f8e Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sat, 30 May 2020 20:49:51 +1000 Subject: [PATCH 08/25] Re-use post type labels for Document label. --- lib/client-assets.php | 24 ------------------- .../sidebar/settings-header/index.js | 24 +++++++++++++++---- .../editor/src/components/provider/index.js | 1 - 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 978d210a4c7ab..c27bd744e0ac8 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -689,30 +689,6 @@ function gutenberg_extend_settings_custom_units( $settings ) { } add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_units' ); -/** - * Extends block editor settings to include UI labels to be shown for elements. - * - * Currently experimental. - * - * @param array $settings Default editor settings. - * @return array Modified editor settings. - */ -function gutenberg_extend_settings_ui_labels( $settings ) { - $post_type = get_post_type(); - $post_type_object = get_post_type_object( $post_type ); - - $document_label = in_array( $post_type, array( 'post', 'page' ), true ) ? - __( 'Document', 'gutenberg' ) : - $post_type_object->labels->singular_name; - - $settings['__experimentalLabels'] = array( - 'document' => $document_label, - ); - - return $settings; -} -add_filter( 'block_editor_settings', 'gutenberg_extend_settings_ui_labels' ); - /* * Register default patterns if not registered in Core already. */ diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 83418ac080112..1a10964b48bf9 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { get } from 'lodash'; + /** * WordPress dependencies */ @@ -11,17 +16,26 @@ const SettingsHeader = ( { sidebarName, } ) => { const documentLabel = useSelect( ( select ) => { - const settings = select( 'core/block-editor' ).getSettings(); - // translators: ARIA label for the Document sidebar tab, not selected. - return settings?.__experimentalLabels?.document ?? __( 'Document' ); + const currentPostType = select( 'core/editor' ).getCurrentPostType(); + const postType = select( 'core' ).getPostType( currentPostType ); + + // translators: Default ARIA label for the Document sidebar tab, not selected. + const defaultDocumentLabel = __( 'Document' ); + + return [ 'post', 'page' ].includes( currentPostType ) + ? defaultDocumentLabel + : get( + postType, + [ 'labels', 'singular_name' ], + defaultDocumentLabel + ); } ); const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. [ sprintf( __( '%1$s (selected)' ), documentLabel ), 'is-active' ] - : // translators: ARIA label for the Document sidebar tab, not selected. - [ documentLabel, '' ]; + : [ documentLabel, '' ]; const blockLabel = __( 'Block' ); const [ blockAriaLabel, blockActiveClass ] = diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index afab87413fbfb..074f93fe2ae1f 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -122,7 +122,6 @@ class EditorProvider extends Component { '__experimentalFeatures', '__experimentalGlobalStylesUserEntityId', '__experimentalGlobalStylesBase', - '__experimentalLabels', '__experimentalPreferredStyleVariations', 'alignWide', 'allowedBlockTypes', From 465f432b27af631f904f4c5c9db13b85d2856257 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sat, 30 May 2020 21:03:18 +1000 Subject: [PATCH 09/25] Clean up & remove extra code. --- .../src/components/sidebar/settings-header/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 1a10964b48bf9..57b2504752f2a 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -15,11 +15,13 @@ const SettingsHeader = ( { openBlockSettings, sidebarName, } ) => { + // translators: Label for the Block Settings Sidebar tab, not selected. + const blockLabel = __( 'Block' ); const documentLabel = useSelect( ( select ) => { const currentPostType = select( 'core/editor' ).getCurrentPostType(); const postType = select( 'core' ).getPostType( currentPostType ); - // translators: Default ARIA label for the Document sidebar tab, not selected. + // translators: Default label for the Document sidebar tab, not selected. const defaultDocumentLabel = __( 'Document' ); return [ 'post', 'page' ].includes( currentPostType ) @@ -37,13 +39,11 @@ const SettingsHeader = ( { [ sprintf( __( '%1$s (selected)' ), documentLabel ), 'is-active' ] : [ documentLabel, '' ]; - const blockLabel = __( 'Block' ); const [ blockAriaLabel, blockActiveClass ] = sidebarName === 'edit-post/block' - ? // translators: ARIA label for the Settings Sidebar tab, selected. - [ __( 'Block (selected)' ), 'is-active' ] - : // translators: ARIA label for the Settings Sidebar tab, not selected. - [ __( 'Block' ), '' ]; + ? // translators: ARIA label for the Block Settings Sidebar tab, selected. + [ sprintf( __( '%1$s (selected)' ), blockLabel ), 'is-active' ] + : [ blockLabel, '' ]; /* Use a list so screen readers will announce how many tabs there are. */ return ( From bd6957a14e886f06188f79dc24e190cbbd7e81a5 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sat, 30 May 2020 21:04:43 +1000 Subject: [PATCH 10/25] Fix typo. --- .../edit-post/src/components/sidebar/settings-header/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 57b2504752f2a..9dc075b216861 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -21,7 +21,7 @@ const SettingsHeader = ( { const currentPostType = select( 'core/editor' ).getCurrentPostType(); const postType = select( 'core' ).getPostType( currentPostType ); - // translators: Default label for the Document sidebar tab, not selected. + // translators: Default ARIA label for the Document sidebar tab, not selected. const defaultDocumentLabel = __( 'Document' ); return [ 'post', 'page' ].includes( currentPostType ) From 38cb8f679650f1139354628dfe649b545e551390 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sat, 27 Jun 2020 20:22:13 +1000 Subject: [PATCH 11/25] Use post type label in Document settings tab in sidebar for all post type. --- .../sidebar/settings-header/index.js | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 9dc075b216861..b2d8fc25f6312 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -8,15 +8,14 @@ import { get } from 'lodash'; */ import { Button } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; -import { withDispatch, useSelect } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; -const SettingsHeader = ( { - openDocumentSettings, - openBlockSettings, - sidebarName, -} ) => { +const SettingsHeader = ( { sidebarName } ) => { // translators: Label for the Block Settings Sidebar tab, not selected. const blockLabel = __( 'Block' ); + + const { openGeneralSidebar } = useDispatch( 'core/edit-post' ); + const documentLabel = useSelect( ( select ) => { const currentPostType = select( 'core/editor' ).getCurrentPostType(); const postType = select( 'core' ).getPostType( currentPostType ); @@ -24,13 +23,11 @@ const SettingsHeader = ( { // translators: Default ARIA label for the Document sidebar tab, not selected. const defaultDocumentLabel = __( 'Document' ); - return [ 'post', 'page' ].includes( currentPostType ) - ? defaultDocumentLabel - : get( - postType, - [ 'labels', 'singular_name' ], - defaultDocumentLabel - ); + return get( + postType, + [ 'labels', 'singular_name' ], + defaultDocumentLabel + ); } ); const [ documentAriaLabel, documentActiveClass ] = @@ -50,7 +47,7 @@ const SettingsHeader = ( {
    From 7f246734d3f262e9fdce4edccda08ba721b4f725 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Wed, 22 Jul 2020 23:27:17 +1000 Subject: [PATCH 18/25] Update packages/edit-post/src/components/sidebar/settings-header/index.js Co-authored-by: Pascal Birchler --- .../edit-post/src/components/sidebar/settings-header/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 38d26e6e4722d..d6d2ed45cc3ff 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -35,7 +35,7 @@ const SettingsHeader = ( { sidebarName } ) => { const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? // translators: ARIA label for the Document sidebar tab, selected. - [ sprintf( __( '%1$s (selected)' ), documentLabel ), 'is-active' ] + [ sprintf( __( '%s (selected)' ), documentLabel ), 'is-active' ] : [ documentLabel, '' ]; const [ blockAriaLabel, blockActiveClass ] = From fbb64d433df3969207412a1b529fcf3aed2dfb75 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Wed, 22 Jul 2020 23:27:30 +1000 Subject: [PATCH 19/25] Update packages/edit-post/src/components/sidebar/settings-header/index.js Co-authored-by: Pascal Birchler --- .../edit-post/src/components/sidebar/settings-header/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index d6d2ed45cc3ff..27a3ee342ec77 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -34,7 +34,7 @@ const SettingsHeader = ( { sidebarName } ) => { const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' - ? // translators: ARIA label for the Document sidebar tab, selected. + ? // translators: ARIA label for the Document sidebar tab, selected. %s: Document label. [ sprintf( __( '%s (selected)' ), documentLabel ), 'is-active' ] : [ documentLabel, '' ]; From 14f0f0a9c1607480f8c15179c02273e78fa9e5dc Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Wed, 22 Jul 2020 23:37:34 +1000 Subject: [PATCH 20/25] Fix nits. --- .../src/components/sidebar/settings-header/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 27a3ee342ec77..599b79d6b02e7 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -17,6 +17,9 @@ const BLOCK_SELECTED_LABEL = __( 'Block (selected)' ); const SettingsHeader = ( { sidebarName } ) => { const { openGeneralSidebar } = useDispatch( 'core/edit-post' ); + const openDocumentSettings = () => + openGeneralSidebar( 'edit-post/document' ); + const openBlockSettings = () => openGeneralSidebar( 'edit-post/block' ); const documentLabel = useSelect( ( select ) => { const currentPostType = select( 'core/editor' ).getCurrentPostType(); @@ -48,7 +51,7 @@ const SettingsHeader = ( { sidebarName } ) => {
    From 92b292d93859564ed5cd988f9677a73d1a114b1b Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Thu, 23 Jul 2020 00:06:11 +1000 Subject: [PATCH 22/25] Fix nits. --- .../sidebar/settings-header/index.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/settings-header/index.js b/packages/edit-post/src/components/sidebar/settings-header/index.js index 38a24281b4d2f..6a144d4daeb2b 100644 --- a/packages/edit-post/src/components/sidebar/settings-header/index.js +++ b/packages/edit-post/src/components/sidebar/settings-header/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -20,13 +15,12 @@ const SettingsHeader = ( { sidebarName } ) => { const currentPostType = select( 'core/editor' ).getCurrentPostType(); const postType = select( 'core' ).getPostType( currentPostType ); - // translators: Default label for the Document sidebar tab, not selected. - const defaultDocumentLabel = __( 'Document' ); - - return get( - postType, - [ 'labels', 'singular_name' ], - defaultDocumentLabel + return ( + // Disable reason: Post type labels object is shaped like this. + // eslint-disable-next-line camelcase + postType?.labels?.singular_name ?? + // translators: Default label for the Document sidebar tab, not selected. + __( 'Document' ) ); } ); From ea95b73b3dbdd901432b6a0c33ff0b535ce263fa Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Fri, 24 Jul 2020 22:36:46 +1000 Subject: [PATCH 23/25] Add shim to override post type labels for Reusable blocks. --- lib/compat.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/compat.php b/lib/compat.php index 03bd469c912f1..b0eb74c9dba1a 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -656,3 +656,42 @@ function gutenberg_preload_edit_post( $preload_paths ) { } add_filter( 'block_editor_preload_paths', 'gutenberg_preload_edit_post' ); + +/** + * Override post type labels for Reusable Block custom post type. + * + * This shim can be removed when the Gutenberg plugin requires a WordPress + * version that has the ticket below. + * + * @see TODO: Add Trac Link. + * + * @since 8.6.0 + * + * @return array Array of new labels for Reusable Block post type. + */ +function gutenberg_override_reusable_block_post_type_labels() { + return array( + 'name' => _x( 'Reusable Blocks', 'post type general name' ), + 'singular_name' => _x( 'Reusable Block', 'post type singular name' ), + 'menu_name' => _x( 'Reusable Blocks', 'admin menu' ), + 'name_admin_bar' => _x( 'Reusable Block', 'add new on admin bar' ), + 'add_new' => _x( 'Add New', 'Block' ), + 'add_new_item' => __( 'Add New Reusable Block' ), + 'new_item' => __( 'New Reusable Block' ), + 'edit_item' => __( 'Edit Reusable Block' ), + 'view_item' => __( 'View Reusable Block' ), + 'all_items' => __( 'All Reusable Blocks' ), + 'search_items' => __( 'Search Reusable Blocks' ), + 'not_found' => __( 'No reusable blocks found.' ), + 'not_found_in_trash' => __( 'No reusable blocks found in Trash.' ), + 'filter_items_list' => __( 'Filter reusable blocks list' ), + 'items_list_navigation' => __( 'Reusable Blocks list navigation' ), + 'items_list' => __( 'Reusable Blocks list' ), + 'item_published' => __( 'Reusable Block published.' ), + 'item_published_privately' => __( 'Reusable Block published privately.' ), + 'item_reverted_to_draft' => __( 'Reusable Block reverted to draft.' ), + 'item_scheduled' => __( 'Reusable Block scheduled.' ), + 'item_updated' => __( 'Reusable Block updated.' ), + ); +} +add_filter( 'post_type_labels_wp_block', 'gutenberg_override_reusable_block_post_type_labels', 10, 0 ); From aa791f1797cc3eb9f52cbc0fe22a7be3a55e82e5 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Fri, 24 Jul 2020 22:50:29 +1000 Subject: [PATCH 24/25] Adds trac link. --- lib/compat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat.php b/lib/compat.php index b0eb74c9dba1a..95455468ce8ef 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -663,7 +663,7 @@ function gutenberg_preload_edit_post( $preload_paths ) { * This shim can be removed when the Gutenberg plugin requires a WordPress * version that has the ticket below. * - * @see TODO: Add Trac Link. + * @see https://core.trac.wordpress.org/ticket/50755 * * @since 8.6.0 * From b9e551b4e7fcbcc0455d7f41f853a486cafe43ae Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Fri, 24 Jul 2020 22:55:15 +1000 Subject: [PATCH 25/25] Fix i18n. --- lib/compat.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/compat.php b/lib/compat.php index 95455468ce8ef..5941bbb1f23b8 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -671,27 +671,27 @@ function gutenberg_preload_edit_post( $preload_paths ) { */ function gutenberg_override_reusable_block_post_type_labels() { return array( - 'name' => _x( 'Reusable Blocks', 'post type general name' ), - 'singular_name' => _x( 'Reusable Block', 'post type singular name' ), - 'menu_name' => _x( 'Reusable Blocks', 'admin menu' ), - 'name_admin_bar' => _x( 'Reusable Block', 'add new on admin bar' ), - 'add_new' => _x( 'Add New', 'Block' ), - 'add_new_item' => __( 'Add New Reusable Block' ), - 'new_item' => __( 'New Reusable Block' ), - 'edit_item' => __( 'Edit Reusable Block' ), - 'view_item' => __( 'View Reusable Block' ), - 'all_items' => __( 'All Reusable Blocks' ), - 'search_items' => __( 'Search Reusable Blocks' ), - 'not_found' => __( 'No reusable blocks found.' ), - 'not_found_in_trash' => __( 'No reusable blocks found in Trash.' ), - 'filter_items_list' => __( 'Filter reusable blocks list' ), - 'items_list_navigation' => __( 'Reusable Blocks list navigation' ), - 'items_list' => __( 'Reusable Blocks list' ), - 'item_published' => __( 'Reusable Block published.' ), - 'item_published_privately' => __( 'Reusable Block published privately.' ), - 'item_reverted_to_draft' => __( 'Reusable Block reverted to draft.' ), - 'item_scheduled' => __( 'Reusable Block scheduled.' ), - 'item_updated' => __( 'Reusable Block updated.' ), + 'name' => _x( 'Reusable Blocks', 'post type general name', 'gutenberg' ), + 'singular_name' => _x( 'Reusable Block', 'post type singular name', 'gutenberg' ), + 'menu_name' => _x( 'Reusable Blocks', 'admin menu', 'gutenberg' ), + 'name_admin_bar' => _x( 'Reusable Block', 'add new on admin bar', 'gutenberg' ), + 'add_new' => _x( 'Add New', 'Reusable Block', 'gutenberg' ), + 'add_new_item' => __( 'Add New Reusable Block', 'gutenberg' ), + 'new_item' => __( 'New Reusable Block', 'gutenberg' ), + 'edit_item' => __( 'Edit Reusable Block', 'gutenberg' ), + 'view_item' => __( 'View Reusable Block', 'gutenberg' ), + 'all_items' => __( 'All Reusable Blocks', 'gutenberg' ), + 'search_items' => __( 'Search Reusable Blocks', 'gutenberg' ), + 'not_found' => __( 'No reusable blocks found.', 'gutenberg' ), + 'not_found_in_trash' => __( 'No reusable blocks found in Trash.', 'gutenberg' ), + 'filter_items_list' => __( 'Filter reusable blocks list', 'gutenberg' ), + 'items_list_navigation' => __( 'Reusable Blocks list navigation', 'gutenberg' ), + 'items_list' => __( 'Reusable Blocks list', 'gutenberg' ), + 'item_published' => __( 'Reusable Block published.', 'gutenberg' ), + 'item_published_privately' => __( 'Reusable Block published privately.', 'gutenberg' ), + 'item_reverted_to_draft' => __( 'Reusable Block reverted to draft.', 'gutenberg' ), + 'item_scheduled' => __( 'Reusable Block scheduled.', 'gutenberg' ), + 'item_updated' => __( 'Reusable Block updated.', 'gutenberg' ), ); } add_filter( 'post_type_labels_wp_block', 'gutenberg_override_reusable_block_post_type_labels', 10, 0 );