From c6c402d4999c1cbc24c6b526e15d7fc42b7b613b Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 23 Sep 2024 08:30:36 +0100 Subject: [PATCH 1/3] Editor: Remove edit template menu item from block settings menu --- .../content-only-settings-menu.js | 74 +++++-------------- 1 file changed, 17 insertions(+), 57 deletions(-) diff --git a/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js b/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js index c772a062b9e3be..264f4c566059c5 100644 --- a/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js +++ b/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js @@ -15,65 +15,38 @@ import { __, _x } from '@wordpress/i18n'; /** * Internal dependencies */ -import { store as editorStore } from '../../store'; import { unlock } from '../../lock-unlock'; -import usePostContentBlocks from '../provider/use-post-content-blocks'; function ContentOnlySettingsMenuItems( { clientId, onClose } ) { - const postContentBlocks = usePostContentBlocks(); const { entity, onNavigateToEntityRecord, canEditTemplates } = useSelect( ( select ) => { const { getBlockParentsByBlockName, getSettings, getBlockAttributes, - } = select( blockEditorStore ); + } = unlock( select( blockEditorStore ) ); const patternParent = getBlockParentsByBlockName( clientId, 'core/block', true )[ 0 ]; - let record; - if ( patternParent ) { - record = select( coreStore ).getEntityRecord( - 'postType', - 'wp_block', - getBlockAttributes( patternParent ).ref - ); - } else { - const { getCurrentTemplateId } = select( editorStore ); - const templateId = getCurrentTemplateId(); - const { getBlockParents } = unlock( - select( blockEditorStore ) - ); - if ( - ! getBlockParents( clientId ).some( ( parent ) => - postContentBlocks.includes( parent ) - ) - ) { - record = select( coreStore ).getEntityRecord( - 'postType', - 'wp_template', - templateId - ); - } - } - if ( ! record ) { - return {}; - } const _canEditTemplates = select( coreStore ).canUser( 'create', { kind: 'postType', name: 'wp_template', } ); return { canEditTemplates: _canEditTemplates, - entity: record, + entity: select( coreStore ).getEntityRecord( + 'postType', + 'wp_block', + getBlockAttributes( patternParent ).ref + ), onNavigateToEntityRecord: getSettings().onNavigateToEntityRecord, }; }, - [ clientId, postContentBlocks ] + [ clientId ] ); if ( ! entity ) { @@ -85,21 +58,6 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) { ); } - const isPattern = entity.type === 'wp_block'; - let helpText = isPattern - ? __( - 'Edit the pattern to move, delete, or make further changes to this block.' - ) - : __( - 'Edit the template to move, delete, or make further changes to this block.' - ); - - if ( ! canEditTemplates ) { - helpText = __( - 'Only users with permissions to edit the template can move or delete this block' - ); - } - return ( <> @@ -112,16 +70,18 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) { } } disabled={ ! canEditTemplates } > - { isPattern ? __( 'Edit pattern' ) : __( 'Edit template' ) } + { __( 'Edit pattern' ) } + + { __( + 'Edit the pattern to move, delete, or make further changes to this block.' + ) } + - - { helpText } - ); } From 4685818340150969747632211f07dc0ba1549783 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 23 Sep 2024 09:45:33 +0100 Subject: [PATCH 2/3] Small fix --- .../content-only-settings-menu.js | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js b/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js index 264f4c566059c5..6daea413ee3b44 100644 --- a/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js +++ b/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js @@ -18,7 +18,7 @@ import { __, _x } from '@wordpress/i18n'; import { unlock } from '../../lock-unlock'; function ContentOnlySettingsMenuItems( { clientId, onClose } ) { - const { entity, onNavigateToEntityRecord, canEditTemplates } = useSelect( + const { entity, onNavigateToEntityRecord } = useSelect( ( select ) => { const { getBlockParentsByBlockName, @@ -30,18 +30,14 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) { 'core/block', true )[ 0 ]; - - const _canEditTemplates = select( coreStore ).canUser( 'create', { - kind: 'postType', - name: 'wp_template', - } ); return { - canEditTemplates: _canEditTemplates, - entity: select( coreStore ).getEntityRecord( - 'postType', - 'wp_block', - getBlockAttributes( patternParent ).ref - ), + entity: + patternParent && + select( coreStore ).getEntityRecord( + 'postType', + 'wp_block', + getBlockAttributes( patternParent ).ref + ), onNavigateToEntityRecord: getSettings().onNavigateToEntityRecord, }; @@ -68,20 +64,19 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) { postType: entity.type, } ); } } - disabled={ ! canEditTemplates } > { __( 'Edit pattern' ) } - - { __( - 'Edit the pattern to move, delete, or make further changes to this block.' - ) } - + + { __( + 'Edit the pattern to move, delete, or make further changes to this block.' + ) } + ); } From 38326bd6924c64da73448c02ccf853c5da5062ad Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 23 Sep 2024 10:11:21 +0100 Subject: [PATCH 3/3] Restore edit template menu --- .../content-only-settings-menu.js | 70 +++++++++++++++---- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js b/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js index 6daea413ee3b44..af0e9b30ae83b4 100644 --- a/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js +++ b/packages/editor/src/components/block-settings-menu/content-only-settings-menu.js @@ -15,34 +15,62 @@ import { __, _x } from '@wordpress/i18n'; /** * Internal dependencies */ +import { store as editorStore } from '../../store'; import { unlock } from '../../lock-unlock'; +import usePostContentBlocks from '../provider/use-post-content-blocks'; function ContentOnlySettingsMenuItems( { clientId, onClose } ) { - const { entity, onNavigateToEntityRecord } = useSelect( + const postContentBlocks = usePostContentBlocks(); + const { entity, onNavigateToEntityRecord, canEditTemplates } = useSelect( ( select ) => { const { getBlockParentsByBlockName, getSettings, getBlockAttributes, - } = unlock( select( blockEditorStore ) ); + getBlockParents, + } = select( blockEditorStore ); + const { getCurrentTemplateId, getRenderingMode } = + select( editorStore ); const patternParent = getBlockParentsByBlockName( clientId, 'core/block', true )[ 0 ]; + + let record; + if ( patternParent ) { + record = select( coreStore ).getEntityRecord( + 'postType', + 'wp_block', + getBlockAttributes( patternParent ).ref + ); + } else if ( + getRenderingMode() === 'template-locked' && + ! getBlockParents( clientId ).some( ( parent ) => + postContentBlocks.includes( parent ) + ) + ) { + record = select( coreStore ).getEntityRecord( + 'postType', + 'wp_template', + getCurrentTemplateId() + ); + } + if ( ! record ) { + return {}; + } + const _canEditTemplates = select( coreStore ).canUser( 'create', { + kind: 'postType', + name: 'wp_template', + } ); return { - entity: - patternParent && - select( coreStore ).getEntityRecord( - 'postType', - 'wp_block', - getBlockAttributes( patternParent ).ref - ), + canEditTemplates: _canEditTemplates, + entity: record, onNavigateToEntityRecord: getSettings().onNavigateToEntityRecord, }; }, - [ clientId ] + [ clientId, postContentBlocks ] ); if ( ! entity ) { @@ -54,6 +82,21 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) { ); } + const isPattern = entity.type === 'wp_block'; + let helpText = isPattern + ? __( + 'Edit the pattern to move, delete, or make further changes to this block.' + ) + : __( + 'Edit the template to move, delete, or make further changes to this block.' + ); + + if ( ! canEditTemplates ) { + helpText = __( + 'Only users with permissions to edit the template can move or delete this block' + ); + } + return ( <> @@ -64,8 +107,9 @@ function ContentOnlySettingsMenuItems( { clientId, onClose } ) { postType: entity.type, } ); } } + disabled={ ! canEditTemplates } > - { __( 'Edit pattern' ) } + { isPattern ? __( 'Edit pattern' ) : __( 'Edit template' ) } - { __( - 'Edit the pattern to move, delete, or make further changes to this block.' - ) } + { helpText } );