From 5bd036b2c982d774ce69fcef59849a70220c91ba Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 13 Feb 2024 11:56:44 +0100 Subject: [PATCH] Fix layout for non viewable post types (#58962) Co-authored-by: youknowriad Co-authored-by: glendaviesnz Co-authored-by: t-hamano --- .../src/components/editor-canvas/index.js | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/editor-canvas/index.js b/packages/editor/src/components/editor-canvas/index.js index f011f285644c0..bc7d54583afbd 100644 --- a/packages/editor/src/components/editor-canvas/index.js +++ b/packages/editor/src/components/editor-canvas/index.js @@ -40,6 +40,17 @@ const { const noop = () => {}; +/** + * These post types have a special editor where they don't allow you to fill the title + * and they don't apply the layout styles. + */ +const DESIGN_POST_TYPES = [ + 'wp_block', + 'wp_template', + 'wp_navigation', + 'wp_template_part', +]; + /** * Given an array of nested blocks, find the first Post Content * block inside it, recursing through any nesting levels, @@ -93,6 +104,7 @@ function EditorCanvas( { wrapperUniqueId, deviceType, showEditorPadding, + isDesignPostType, } = useSelect( ( select ) => { const { getCurrentPostId, @@ -130,6 +142,7 @@ function EditorCanvas( { return { renderingMode: _renderingMode, postContentAttributes: editorSettings.postContentAttributes, + isDesignPostType: DESIGN_POST_TYPES.includes( postTypeSlug ), // Post template fetch returns a 404 on classic themes, which // messes with e2e tests, so check it's a block theme first. editedPostTemplate: @@ -164,7 +177,7 @@ function EditorCanvas( { // fallbackLayout is used if there is no Post Content, // and for Post Title. const fallbackLayout = useMemo( () => { - if ( renderingMode !== 'post-only' ) { + if ( renderingMode !== 'post-only' || isDesignPostType ) { return { type: 'default' }; } @@ -175,7 +188,12 @@ function EditorCanvas( { } // Set default layout for classic themes so all alignments are supported. return { type: 'default' }; - }, [ renderingMode, themeSupportsLayout, globalLayoutSettings ] ); + }, [ + renderingMode, + themeSupportsLayout, + globalLayoutSettings, + isDesignPostType, + ] ); const newestPostContentAttributes = useMemo( () => { if ( @@ -318,7 +336,8 @@ function EditorCanvas( { > { themeSupportsLayout && ! themeHasDisabledLayoutStyles && - renderingMode === 'post-only' && ( + renderingMode === 'post-only' && + ! isDesignPostType && ( <> ) } - { renderingMode === 'post-only' && ( + { renderingMode === 'post-only' && ! isDesignPostType && (