Skip to content

Commit

Permalink
Change name to canUserEditValue
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed May 28, 2024
1 parent 889e0f4 commit d35db11
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 44 deletions.
5 changes: 2 additions & 3 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ export function RichTextWrapper(
break;
}

// If the source is not defined, or if its value of `lockAttributesEditing` is `true`, disable it.
// If the source is not defined, or if its value of `canUserEditValue` is `false`, disable it.
const blockBindingsSource = getBlockBindingsSource(
binding.source
);
if (
! blockBindingsSource ||
blockBindingsSource.lockAttributesEditing( {
! blockBindingsSource?.canUserEditValue( {
select,
context:
select( blockEditorStore ).getBlockContext(
Expand Down
11 changes: 5 additions & 6 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,11 @@ function ButtonEdit( props ) {
return {
lockUrlControls:
!! metadata?.bindings?.url &&
( ! blockBindingsSource ||
blockBindingsSource?.lockAttributesEditing( {
select,
context,
args: metadata?.bindings?.url?.args,
} ) ),
! blockBindingsSource?.canUserEditValue( {
select,
context,
args: metadata?.bindings?.url?.args,
} ),
};
},
[ isSelected ]
Expand Down
11 changes: 5 additions & 6 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,11 @@ export function ImageEdit( {
return {
lockUrlControls:
!! metadata?.bindings?.url &&
( ! blockBindingsSource ||
blockBindingsSource?.lockAttributesEditing( {
select,
context,
args: metadata?.bindings?.url?.args,
} ) ),
! blockBindingsSource?.canUserEditValue( {
select,
context,
args: metadata?.bindings?.url?.args,
} ),
lockUrlControlsMessage: blockBindingsSource?.label
? sprintf(
/* translators: %s: Label of the bindings source. */
Expand Down
33 changes: 15 additions & 18 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,11 @@ export default function Image( {
return {
lockUrlControls:
!! urlBinding &&
( ! urlBindingSource ||
urlBindingSource?.lockAttributesEditing( {
select,
context,
args: urlBinding?.args,
} ) ),
! urlBindingSource?.canUserEditValue( {
select,
context,
args: urlBinding?.args,
} ),
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.
Expand All @@ -478,12 +477,11 @@ export default function Image( {
hasParentPattern,
lockAltControls:
!! altBinding &&
( ! altBindingSource ||
altBindingSource?.lockAttributesEditing( {
select,
context,
args: altBinding?.args,
} ) ),
! altBindingSource?.canUserEditValue( {
select,
context,
args: altBinding?.args,
} ),
lockAltControlsMessage: altBindingSource?.label
? sprintf(
/* translators: %s: Label of the bindings source. */
Expand All @@ -493,12 +491,11 @@ export default function Image( {
: __( 'Connected to dynamic data' ),
lockTitleControls:
!! titleBinding &&
( ! titleBindingSource ||
titleBindingSource?.lockAttributesEditing( {
select,
context,
args: titleBinding?.args,
} ) ),
! titleBindingSource?.canUserEditValue( {
select,
context,
args: titleBinding?.args,
} ),
lockTitleControlsMessage: titleBindingSource?.label
? sprintf(
/* translators: %s: Label of the bindings source. */
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ export function registerBlockBindingsSource( source ) {
setValue: source.setValue,
setValues: source.setValues,
getPlaceholder: source.getPlaceholder,
lockAttributesEditing: source.lockAttributesEditing,
canUserEditValue: source.canUserEditValue,
};
}
3 changes: 1 addition & 2 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ export function blockBindingsSources( state = {}, action ) {
setValue: action.setValue,
setValues: action.setValues,
getPlaceholder: action.getPlaceholder,
lockAttributesEditing:
action.lockAttributesEditing || ( () => true ),
canUserEditValue: action.canUserEditValue || ( () => false ),
},
};
}
Expand Down
4 changes: 1 addition & 3 deletions packages/editor/src/bindings/pattern-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,5 @@ export default {
},
} );
},
lockAttributesEditing() {
return false;
},
canUserEditValue: () => true,
};
10 changes: 5 additions & 5 deletions packages/editor/src/bindings/post-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ export default {
},
} );
},
lockAttributesEditing( { select, context, args } ) {
canUserEditValue( { select, context, args } ) {
const postType =
context?.postType || select( editorStore ).getCurrentPostType();

// Check that editing is happening in the post editor and not a template.
if ( postType === 'wp_template' ) {
return true;
return false;
}

// Check that the custom field is not protected and available in the REST API.
const isFieldExposed =
select( editorStore ).getEditedPostAttribute( 'meta' )[ args.key ];
if ( ! isFieldExposed ) {
return true;
return false;
}

// Check that the user has the capability to edit post meta.
Expand All @@ -54,9 +54,9 @@ export default {
context?.postId
);
if ( ! canUserEdit ) {
return true;
return false;
}

return false;
return true;
},
};

0 comments on commit d35db11

Please sign in to comment.