Skip to content

Commit c41857c

Browse files
ellatrixtalldanSantosGuillamotcarolinanafercia
authored
Pattern overrides: disallow override for image with caption/href (#62747)
Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: afercia <afercia@git.wordpress.org>
1 parent 9b945db commit c41857c

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

packages/block-library/src/image/image.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ export default function Image( {
426426
</InspectorControls>
427427
);
428428

429+
const arePatternOverridesEnabled =
430+
metadata?.bindings?.__default?.source === 'core/pattern-overrides';
431+
429432
const {
430433
lockUrlControls = false,
431434
lockHrefControls = false,
@@ -470,7 +473,7 @@ export default function Image( {
470473
lockHrefControls:
471474
// Disable editing the link of the URL if the image is inside a pattern instance.
472475
// This is a temporary solution until we support overriding the link on the frontend.
473-
hasParentPattern,
476+
hasParentPattern || arePatternOverridesEnabled,
474477
lockCaption:
475478
// Disable editing the caption if the image is inside a pattern instance.
476479
// This is a temporary solution until we support overriding the caption on the frontend.
@@ -971,7 +974,11 @@ export default function Image( {
971974
isSelected={ isSingleSelected }
972975
insertBlocksAfter={ insertBlocksAfter }
973976
label={ __( 'Image caption text' ) }
974-
showToolbarButton={ isSingleSelected && hasNonContentControls }
977+
showToolbarButton={
978+
isSingleSelected &&
979+
hasNonContentControls &&
980+
! arePatternOverridesEnabled
981+
}
975982
readOnly={ lockCaption }
976983
/>
977984
</>

packages/editor/src/hooks/pattern-overrides.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ const {
3434
*/
3535
const withPatternOverrideControls = createHigherOrderComponent(
3636
( BlockEdit ) => ( props ) => {
37-
const isSupportedBlock = Object.keys(
38-
PARTIAL_SYNCING_SUPPORTED_BLOCKS
39-
).includes( props.name );
37+
const isSupportedBlock =
38+
!! PARTIAL_SYNCING_SUPPORTED_BLOCKS[ props.name ];
4039

4140
return (
4241
<>

packages/patterns/src/components/pattern-overrides-controls.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function addBindings( bindings ) {
3131
};
3232
}
3333

34-
function PatternOverridesControls( { attributes, setAttributes } ) {
34+
function PatternOverridesControls( {
35+
attributes,
36+
setAttributes,
37+
name: blockName,
38+
} ) {
3539
const controlId = useId();
3640
const [ showAllowOverridesModal, setShowAllowOverridesModal ] =
3741
useState( false );
@@ -71,15 +75,25 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
7175
return null;
7276
}
7377

78+
const hasUnsupportedImageAttributes =
79+
blockName === 'core/image' &&
80+
( !! attributes.caption?.length || !! attributes.href?.length );
81+
82+
const helpText = hasUnsupportedImageAttributes
83+
? __(
84+
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
85+
)
86+
: __(
87+
'Allow changes to this block throughout instances of this pattern.'
88+
);
89+
7490
return (
7591
<>
7692
<InspectorControls group="advanced">
7793
<BaseControl
7894
id={ controlId }
7995
label={ __( 'Overrides' ) }
80-
help={ __(
81-
'Allow changes to this block throughout instances of this pattern.'
82-
) }
96+
help={ helpText }
8397
>
8498
<Button
8599
__next40pxDefaultSize
@@ -93,6 +107,8 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
93107
setShowAllowOverridesModal( true );
94108
}
95109
} }
110+
disabled={ hasUnsupportedImageAttributes }
111+
__experimentalIsFocusable
96112
>
97113
{ allowOverrides
98114
? __( 'Disable overrides' )

0 commit comments

Comments
 (0)