Skip to content

Commit e8896b9

Browse files
committed
add post type content support check for zoom out availability
1 parent b95553f commit e8896b9

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

docs/reference-guides/data/data-core-editor.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,18 @@ _Returns_
555555
556556
- `string|undefined`: The post type label if available, otherwise undefined.
557557
558+
### getPostTypeSupports
559+
560+
Returns a post type support object on the current post
561+
562+
_Parameters_
563+
564+
- _state_ `Object`: Global application state.
565+
566+
_Returns_
567+
568+
- `Object`: The post type supports object.
569+
558570
### getPreviousBlockClientId
559571
560572
_Related_

lib/init.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,27 @@ function gutenberg_menu() {
5757
);
5858
}
5959
add_action( 'admin_menu', 'gutenberg_menu', 9 );
60+
61+
62+
/**
63+
* This should be implemented in core as a default
64+
* post type feature.
65+
*
66+
*/
67+
if ( ! function_exists( 'add_content_support' ) ) {
68+
/**
69+
* Add the 'content' support to core content post types.
70+
*
71+
* @since 6.8.0
72+
*/
73+
function add_content_support() {
74+
global $wp_post_types;
75+
76+
foreach ( array_keys( $wp_post_types ) as $post_type ) {
77+
if ( in_array( $post_type, array( 'post', 'page', 'wp_template' ), true ) ) {
78+
add_post_type_support( $post_type, 'content' );
79+
}
80+
}
81+
}
82+
add_action( 'init', 'add_content_support' );
83+
}

packages/editor/src/components/header/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function Header( {
5454
const isLargeViewport = useViewportMatch( 'medium' );
5555
const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' );
5656
const {
57-
postType,
57+
postTypeContentSupport,
5858
isTextEditor,
5959
isPublishSidebarOpened,
6060
showIconLabels,
@@ -66,12 +66,13 @@ function Header( {
6666
const {
6767
getEditorMode,
6868
getEditorSettings,
69-
getCurrentPostType,
7069
isPublishSidebarOpened: _isPublishSidebarOpened,
70+
getPostTypeSupports,
7171
} = select( editorStore );
7272

7373
return {
74-
postType: getCurrentPostType(),
74+
postTypeContentSupport:
75+
getPostTypeSupports().hasOwnProperty( 'content' ),
7576
isTextEditor: getEditorMode() === 'text',
7677
isPublishSidebarOpened: _isPublishSidebarOpened(),
7778
showIconLabels: getPreference( 'core', 'showIconLabels' ),
@@ -83,10 +84,6 @@ function Header( {
8384
};
8485
}, [] );
8586

86-
const canBeZoomedOut = [ 'post', 'page', 'wp_template' ].includes(
87-
postType
88-
);
89-
9087
const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] =
9188
useState( true );
9289

@@ -149,9 +146,11 @@ function Header( {
149146
<PostSavedState forceIsDirty={ forceIsDirty } />
150147
) }
151148

152-
{ canBeZoomedOut && isEditorIframed && isWideViewport && (
153-
<ZoomOutToggle disabled={ forceDisableBlockTools } />
154-
) }
149+
{ postTypeContentSupport &&
150+
isEditorIframed &&
151+
isWideViewport && (
152+
<ZoomOutToggle disabled={ forceDisableBlockTools } />
153+
) }
155154

156155
<PreviewDropdown
157156
forceIsAutosaveable={ forceIsDirty }

packages/editor/src/store/selectors.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,21 @@ export const getPostTypeLabel = createRegistrySelector(
18141814
}
18151815
);
18161816

1817+
/**
1818+
* Returns a post type support object on the current post
1819+
*
1820+
* @param {Object} state Global application state.
1821+
*
1822+
* @return {Object} The post type supports object.
1823+
*/
1824+
export const getPostTypeSupports = createRegistrySelector(
1825+
( select ) => ( state ) => {
1826+
const currentPostType = getCurrentPostType( state );
1827+
const postType = select( coreStore ).getPostType( currentPostType );
1828+
return postType?.supports ?? {};
1829+
}
1830+
);
1831+
18171832
/**
18181833
* Returns true if the publish sidebar is opened.
18191834
*

0 commit comments

Comments
 (0)