Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern overrides: Remove caption and href from images with overrides #62775

Closed
Closed
Show file tree
Hide file tree
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
30 changes: 19 additions & 11 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ export default function Image( {
</InspectorControls>
);

const isPatternOverridesEnabled =
metadata?.bindings?.__default?.source === 'core/pattern-overrides';

const {
lockUrlControls = false,
lockHrefControls = false,
Expand Down Expand Up @@ -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( {
Expand Down Expand Up @@ -965,15 +968,20 @@ export default function Image( {
{ controls }
{ img }

<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={ isSingleSelected && hasNonContentControls }
readOnly={ lockCaption }
/>
{ /* Don't add caption in images with pattern overrides until it is supported. */ }
{ ! isPatternOverridesEnabled && (
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={
isSingleSelected && hasNonContentControls
}
readOnly={ lockCaption }
/>
) }
</>
);
}
10 changes: 8 additions & 2 deletions packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function save( { attributes } ) {
linkTarget,
sizeSlug,
title,
metadata,
} = attributes;

const newRel = ! rel ? undefined : rel;
Expand Down Expand Up @@ -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 ? (
<a
className={ linkClass }
href={ href }
Expand All @@ -84,7 +89,8 @@ export default function save( { attributes } ) {
) : (
image
) }
{ ! RichText.isEmpty( caption ) && (
{ /* Don't add caption in images with pattern overrides until it is supported. */ }
{ ! RichText.isEmpty( caption ) && ! isPatternOverridesEnabled && (
<RichText.Content
className={ __experimentalGetElementClassName( 'caption' ) }
tagName="figcaption"
Expand Down
Loading