diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js
index 1986ad8730c121..a18556f2fa5bd9 100644
--- a/packages/block-editor/src/components/block-inspector/index.js
+++ b/packages/block-editor/src/components/block-inspector/index.js
@@ -72,7 +72,6 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
{ ...blockInformation }
className={ blockInformation.isSynced && 'is-synced' }
/>
-
{ hasBlockStyles && (
diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js
index c8ee422091ad1f..98e7f7b2d21420 100644
--- a/packages/block-editor/src/components/block-switcher/index.js
+++ b/packages/block-editor/src/components/block-switcher/index.js
@@ -198,6 +198,7 @@ const BlockIndicator = ( { icon, showTitle, blockTitle } ) => (
export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const {
+ hasContentOnlyLocking,
canRemove,
hasBlockStyles,
icon,
@@ -206,8 +207,12 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
isTemplate,
} = useSelect(
( select ) => {
- const { getBlocksByClientId, getBlockAttributes, canRemoveBlocks } =
- select( blockEditorStore );
+ const {
+ getTemplateLock,
+ getBlocksByClientId,
+ getBlockAttributes,
+ canRemoveBlocks,
+ } = select( blockEditorStore );
const { getBlockStyles, getBlockType, getActiveBlockVariation } =
select( blocksStore );
const _blocks = getBlocksByClientId( clientIds );
@@ -219,6 +224,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const blockType = getBlockType( firstBlockName );
let _icon;
+ let _hasTemplateLock;
if ( _isSingleBlockSelected ) {
const match = getActiveBlockVariation(
firstBlockName,
@@ -226,9 +232,14 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
);
// Take into account active block variations.
_icon = match?.icon || blockType.icon;
+ _hasTemplateLock =
+ getTemplateLock( clientIds[ 0 ] ) === 'contentOnly';
} else {
const isSelectionOfSameType =
new Set( _blocks.map( ( { name } ) => name ) ).size === 1;
+ _hasTemplateLock = clientIds.some(
+ ( id ) => getTemplateLock( id ) === 'contentOnly'
+ );
// When selection consists of blocks of multiple types, display an
// appropriate icon to communicate the non-uniformity.
_icon = isSelectionOfSameType ? blockType.icon : copy;
@@ -244,6 +255,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
_isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ),
isTemplate:
_isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ),
+ hasContentOnlyLocking: _hasTemplateLock,
};
},
[ clientIds ]
@@ -252,6 +264,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
clientId: clientIds?.[ 0 ],
maximumLength: 35,
} );
+
if ( invalidBlocks ) {
return null;
}
@@ -261,7 +274,10 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
? blockTitle
: __( 'Multiple blocks selected' );
- const hideDropdown = disabled || ( ! hasBlockStyles && ! canRemove );
+ const hideDropdown =
+ disabled ||
+ ( ! hasBlockStyles && ! canRemove ) ||
+ hasContentOnlyLocking;
if ( hideDropdown ) {
return (
diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js
index b14ceb50590495..6c4789cb2924f2 100644
--- a/packages/block-editor/src/components/block-toolbar/index.js
+++ b/packages/block-editor/src/components/block-toolbar/index.js
@@ -66,6 +66,7 @@ export function PrivateBlockToolbar( {
showParentSelector,
isUsingBindings,
hasParentPattern,
+ hasContentOnlyLocking,
} = useSelect( ( select ) => {
const {
getBlockName,
@@ -76,6 +77,7 @@ export function PrivateBlockToolbar( {
getBlockEditingMode,
getBlockAttributes,
getBlockParentsByBlockName,
+ getTemplateLock,
} = select( blockEditorStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
@@ -103,6 +105,10 @@ export function PrivateBlockToolbar( {
.length > 0
);
+ // If one or more selected blocks are locked, do not show the BlockGroupToolbar.
+ const _hasTemplateLock = selectedBlockClientIds.some(
+ ( id ) => getTemplateLock( id ) === 'contentOnly'
+ );
return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
@@ -123,6 +129,7 @@ export function PrivateBlockToolbar( {
_isDefaultEditingMode,
isUsingBindings: _isUsingBindings,
hasParentPattern: _hasParentPattern,
+ hasContentOnlyLocking: _hasTemplateLock,
};
}, [] );
@@ -205,9 +212,9 @@ export function PrivateBlockToolbar( {
) }
- { shouldShowVisualToolbar && isMultiToolbar && (
-
- ) }
+ { ! hasContentOnlyLocking &&
+ shouldShowVisualToolbar &&
+ isMultiToolbar && }
{ shouldShowVisualToolbar && (
<>