Skip to content

Commit

Permalink
add post type content support check for zoom out availability
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Oct 30, 2024
1 parent b95553f commit e8896b9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
12 changes: 12 additions & 0 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,18 @@ _Returns_
- `string|undefined`: The post type label if available, otherwise undefined.
### getPostTypeSupports
Returns a post type support object on the current post
_Parameters_
- _state_ `Object`: Global application state.
_Returns_
- `Object`: The post type supports object.
### getPreviousBlockClientId
_Related_
Expand Down
24 changes: 24 additions & 0 deletions lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,27 @@ function gutenberg_menu() {
);
}
add_action( 'admin_menu', 'gutenberg_menu', 9 );


/**
* This should be implemented in core as a default
* post type feature.
*
*/
if ( ! function_exists( 'add_content_support' ) ) {
/**
* Add the 'content' support to core content post types.
*
* @since 6.8.0
*/
function add_content_support() {
global $wp_post_types;

foreach ( array_keys( $wp_post_types ) as $post_type ) {
if ( in_array( $post_type, array( 'post', 'page', 'wp_template' ), true ) ) {
add_post_type_support( $post_type, 'content' );
}
}
}
add_action( 'init', 'add_content_support' );
}
19 changes: 9 additions & 10 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function Header( {
const isLargeViewport = useViewportMatch( 'medium' );
const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' );
const {
postType,
postTypeContentSupport,
isTextEditor,
isPublishSidebarOpened,
showIconLabels,
Expand All @@ -66,12 +66,13 @@ function Header( {
const {
getEditorMode,
getEditorSettings,
getCurrentPostType,
isPublishSidebarOpened: _isPublishSidebarOpened,
getPostTypeSupports,
} = select( editorStore );

return {
postType: getCurrentPostType(),
postTypeContentSupport:
getPostTypeSupports().hasOwnProperty( 'content' ),
isTextEditor: getEditorMode() === 'text',
isPublishSidebarOpened: _isPublishSidebarOpened(),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
Expand All @@ -83,10 +84,6 @@ function Header( {
};
}, [] );

const canBeZoomedOut = [ 'post', 'page', 'wp_template' ].includes(
postType
);

const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] =
useState( true );

Expand Down Expand Up @@ -149,9 +146,11 @@ function Header( {
<PostSavedState forceIsDirty={ forceIsDirty } />
) }

{ canBeZoomedOut && isEditorIframed && isWideViewport && (
<ZoomOutToggle disabled={ forceDisableBlockTools } />
) }
{ postTypeContentSupport &&
isEditorIframed &&
isWideViewport && (
<ZoomOutToggle disabled={ forceDisableBlockTools } />
) }

<PreviewDropdown
forceIsAutosaveable={ forceIsDirty }
Expand Down
15 changes: 15 additions & 0 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,21 @@ export const getPostTypeLabel = createRegistrySelector(
}
);

/**
* Returns a post type support object on the current post
*
* @param {Object} state Global application state.
*
* @return {Object} The post type supports object.
*/
export const getPostTypeSupports = createRegistrySelector(
( select ) => ( state ) => {
const currentPostType = getCurrentPostType( state );
const postType = select( coreStore ).getPostType( currentPostType );
return postType?.supports ?? {};
}
);

/**
* Returns true if the publish sidebar is opened.
*
Expand Down

0 comments on commit e8896b9

Please sign in to comment.