Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ export default function Image( {

const {
lockUrlControls = false,
lockHrefControls = false,
lockAltControls = false,
lockTitleControls = false,
} = useSelect(
Expand All @@ -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 )
Expand All @@ -436,27 +442,30 @@ export default function Image( {
?.lockAttributesEditing === true,
};
},
[ isSingleSelected ]
[ clientId, isSingleSelected, metadata?.bindings ]
);

const controls = (
<>
<BlockControls group="block">
{ isSingleSelected && ! isEditingImage && ! lockUrlControls && (
<ImageURLInputUI
url={ href || '' }
onChangeUrl={ onSetHref }
linkDestination={ linkDestination }
mediaUrl={ ( image && image.source_url ) || url }
mediaLink={ image && image.link }
linkTarget={ linkTarget }
linkClass={ linkClass }
rel={ rel }
showLightboxSetting={ showLightboxSetting }
lightboxEnabled={ lightboxChecked }
onSetLightbox={ onSetLightbox }
/>
) }
{ isSingleSelected &&
! isEditingImage &&
! lockHrefControls &&
! lockUrlControls && (
<ImageURLInputUI
url={ href || '' }
onChangeUrl={ onSetHref }
linkDestination={ linkDestination }
mediaUrl={ ( image && image.source_url ) || url }
mediaLink={ image && image.link }
linkTarget={ linkTarget }
linkClass={ linkClass }
rel={ rel }
showLightboxSetting={ showLightboxSetting }
lightboxEnabled={ lightboxChecked }
onSetLightbox={ onSetLightbox }
/>
) }
{ allowCrop && (
<ToolbarButton
onClick={ () => setIsEditingImage( true ) }
Expand Down