From 35c236700f2b7433cb47f02478815101b49c9343 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Mon, 24 Jun 2024 09:02:37 +0200 Subject: [PATCH] Disallow caption/href in images with overrides --- packages/block-library/src/image/image.js | 30 ++++++++++++++--------- packages/block-library/src/image/save.js | 10 ++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 6095ef2fee24d..1798f29ca8c73 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -426,6 +426,9 @@ export default function Image( { ); + const isPatternOverridesEnabled = + metadata?.bindings?.__default?.source === 'core/pattern-overrides'; + const { lockUrlControls = false, lockHrefControls = false, @@ -470,11 +473,11 @@ export default function Image( { 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, + hasParentPattern || isPatternOverridesEnabled, lockCaption: // Disable editing the caption if the image is inside a pattern instance. // This is a temporary solution until we support overriding the caption on the frontend. - hasParentPattern, + hasParentPattern || isPatternOverridesEnabled, lockAltControls: !! altBinding && ! altBindingSource?.canUserEditValue( { @@ -965,15 +968,20 @@ export default function Image( { { controls } { img } - + { /* Don't add caption in images with pattern overrides until it is supported. */ } + { ! isPatternOverridesEnabled && ( + + ) } ); } diff --git a/packages/block-library/src/image/save.js b/packages/block-library/src/image/save.js index 69c26cde52a9c..c5f9e86f3cb6e 100644 --- a/packages/block-library/src/image/save.js +++ b/packages/block-library/src/image/save.js @@ -31,6 +31,7 @@ export default function save( { attributes } ) { linkTarget, sizeSlug, title, + metadata, } = attributes; const newRel = ! rel ? undefined : rel; @@ -70,9 +71,13 @@ export default function save( { attributes } ) { /> ); + const isPatternOverridesEnabled = + metadata?.bindings?.__default?.source === 'core/pattern-overrides'; + const figure = ( <> - { href ? ( + { /* Don't add links in images with pattern overrides until they are supported. */ } + { href && ! isPatternOverridesEnabled ? (