diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 2eb41467c6b5b..8c911fad726ae 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -405,6 +405,7 @@ export default function Image( { const { lockUrlControls = false, + lockHrefControls = false, lockAltControls = false, lockTitleControls = false, } = useSelect( @@ -413,19 +414,24 @@ export default function Image( { return {}; } - const { getBlockBindingsSource } = unlock( - select( blockEditorStore ) - ); + const { getBlockBindingsSource, getBlockParentsByBlockName } = + unlock( select( blockEditorStore ) ); const { url: urlBinding, alt: altBinding, title: titleBinding, } = metadata?.bindings || {}; + const hasParentPattern = + getBlockParentsByBlockName( clientId, 'core/block' ).length > 0; return { lockUrlControls: !! urlBinding && getBlockBindingsSource( urlBinding?.source ) ?.lockAttributesEditing === true, + lockHrefControls: + // Disable editing the link of the URL if the image is inside a pattern instance. + // This is a temporary solution until we support overriding the link on the frontend. + hasParentPattern, lockAltControls: !! altBinding && getBlockBindingsSource( altBinding?.source ) @@ -436,27 +442,30 @@ export default function Image( { ?.lockAttributesEditing === true, }; }, - [ isSingleSelected ] + [ clientId, isSingleSelected, metadata?.bindings ] ); const controls = ( <> - { isSingleSelected && ! isEditingImage && ! lockUrlControls && ( - - ) } + { isSingleSelected && + ! isEditingImage && + ! lockHrefControls && + ! lockUrlControls && ( + + ) } { allowCrop && ( setIsEditingImage( true ) }