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

Block Bindings: Fix disable bindings editing when source is undefined #58961

Merged
Merged
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
17 changes: 12 additions & 5 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,19 @@ export function RichTextWrapper(
for ( const [ attribute, args ] of Object.entries(
blockBindings
) ) {
// If any of the attributes with source "rich-text" is part of the bindings,
// has a source with `lockAttributesEditing`, disable it.
if (
blockTypeAttributes?.[ attribute ]?.source ===
'rich-text' &&
getBlockBindingsSource( args.source )?.lockAttributesEditing
blockTypeAttributes?.[ attribute ]?.source !== 'rich-text'
) {
break;
}

// If the source is not defined, or if its value of `lockAttributesEditing` is `true`, disable it.
const blockBindingsSource = getBlockBindingsSource(
args.source
);
if (
! blockBindingsSource ||
blockBindingsSource.lockAttributesEditing
) {
shouldDisableEditing = true;
break;
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ function ButtonEdit( props ) {
return {};
}

const { getBlockBindingsSource } = unlock(
const blockBindingsSource = unlock(
select( blockEditorStore )
);
).getBlockBindingsSource( metadata?.bindings?.url?.source );

return {
lockUrlControls:
!! metadata?.bindings?.url &&
getBlockBindingsSource( metadata?.bindings?.url?.source )
?.lockAttributesEditing,
( ! blockBindingsSource ||
blockBindingsSource?.lockAttributesEditing ),
};
},
[ isSelected ]
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ export function ImageEdit( {
return {};
}

const { getBlockBindingsSource } = unlock(
const blockBindingsSource = unlock(
select( blockEditorStore )
);
).getBlockBindingsSource( metadata?.bindings?.url?.source );

return {
lockUrlControls:
!! metadata?.bindings?.url &&
getBlockBindingsSource( metadata?.bindings?.url?.source )
?.lockAttributesEditing,
( ! blockBindingsSource ||
blockBindingsSource?.lockAttributesEditing ),
};
},
[ isSingleSelected ]
Expand Down
21 changes: 15 additions & 6 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,23 +423,32 @@ export default function Image( {
} = metadata?.bindings || {};
const hasParentPattern =
getBlockParentsByBlockName( clientId, 'core/block' ).length > 0;
const urlBindingSource = getBlockBindingsSource(
urlBinding?.source
);
const altBindingSource = getBlockBindingsSource(
altBinding?.source
);
const titleBindingSource = getBlockBindingsSource(
titleBinding?.source
);
return {
lockUrlControls:
!! urlBinding &&
getBlockBindingsSource( urlBinding?.source )
?.lockAttributesEditing,
( ! urlBindingSource ||
urlBindingSource?.lockAttributesEditing ),
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 )
?.lockAttributesEditing,
( ! altBindingSource ||
altBindingSource?.lockAttributesEditing ),
lockTitleControls:
!! titleBinding &&
getBlockBindingsSource( titleBinding?.source )
?.lockAttributesEditing,
( ! titleBindingSource ||
titleBindingSource?.lockAttributesEditing ),
};
},
[ clientId, isSingleSelected, metadata?.bindings ]
Expand Down
Loading
Loading