From 8e0a33cdc602b802b308cfde1939b971349246d0 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:06:30 +0900 Subject: [PATCH 01/12] Polish create template part modal (#63617) * Polish create template part modal * Add focusOnMount prop Co-authored-by: t-hamano Co-authored-by: jameskoster --- .../src/template-part/edit/title-modal.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/template-part/edit/title-modal.js b/packages/block-library/src/template-part/edit/title-modal.js index 0fe4cb08fb8b0d..e1f10c91a67da8 100644 --- a/packages/block-library/src/template-part/edit/title-modal.js +++ b/packages/block-library/src/template-part/edit/title-modal.js @@ -14,7 +14,7 @@ import { export default function TitleModal( { areaLabel, onClose, onSubmit } ) { // Restructure onCreate to set the blocks on local state. // Add modal to confirm title and trigger onCreate. - const [ title, setTitle ] = useState( __( 'Untitled Template Part' ) ); + const [ title, setTitle ] = useState( '' ); const submitForCreation = ( event ) => { event.preventDefault(); @@ -25,26 +25,40 @@ export default function TitleModal( { areaLabel, onClose, onSubmit } ) {
+ From 3099d18e430a70c905b429e4a8b5545daead823b Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:42:45 +0900 Subject: [PATCH 02/12] Template Part: Add check if create action should be allowed (#63623) Co-authored-by: t-hamano Co-authored-by: Mamaduka --- .../src/template-part/edit/placeholder.js | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/template-part/edit/placeholder.js b/packages/block-library/src/template-part/edit/placeholder.js index ff43ee5644ad7c..c7e5e70c970e09 100644 --- a/packages/block-library/src/template-part/edit/placeholder.js +++ b/packages/block-library/src/template-part/edit/placeholder.js @@ -4,6 +4,8 @@ import { __, sprintf } from '@wordpress/i18n'; import { Placeholder, Button, Spinner } from '@wordpress/components'; import { useState } from '@wordpress/element'; +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -28,6 +30,21 @@ export default function TemplatePartPlaceholder( { templatePartId ); const blockPatterns = useAlternativeBlockPatterns( area, clientId ); + + const { isBlockBasedTheme, canCreateTemplatePart } = useSelect( + ( select ) => { + const { getCurrentTheme, canUser } = select( coreStore ); + return { + isBlockBasedTheme: getCurrentTheme()?.is_block_theme, + canCreateTemplatePart: canUser( 'create', { + kind: 'postType', + name: 'wp_template_part', + } ), + }; + }, + [] + ); + const [ showTitleModal, setShowTitleModal ] = useState( false ); const areaObject = useTemplatePartArea( area ); const createFromBlocks = useCreateTemplatePartFromBlocks( @@ -39,11 +56,19 @@ export default function TemplatePartPlaceholder( { { isResolving && } @@ -54,7 +79,7 @@ export default function TemplatePartPlaceholder( { ) } - { ! isResolving && ( + { ! isResolving && isBlockBasedTheme && canCreateTemplatePart && (