Skip to content

Commit

Permalink
Don't use fallback for context
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed May 24, 2024
1 parent d514459 commit 5fdbacb
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions packages/editor/src/bindings/post-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,28 @@ import { store as editorStore } from '../store';
export default {
name: 'core/post-meta',
label: _x( 'Post Meta', 'block bindings source' ),
usesContext: [ 'postId', 'postType' ],
getPlaceholder( { args } ) {
return args.key;
},
getValue( { select, context, args } ) {
const postId =
context?.postId || select( editorStore ).getCurrentPostId();
const postType =
context?.postType || select( editorStore ).getCurrentPostType();

return select( coreDataStore ).getEditedEntityRecord(
'postType',
postType,
postId
context?.postType,
context?.postId
).meta?.[ args.key ];
},
setValue( { registry, context, args, value } ) {
const postId =
context?.postId ||
registry.select( editorStore ).getCurrentPostId();
const postType =
context?.postType ||
registry.select( editorStore ).getCurrentPostType();
registry
.dispatch( coreDataStore )
.editEntityRecord( 'postType', postType, postId, {
.editEntityRecord( 'postType', context?.postType, context?.postId, {
meta: {
[ args.key ]: value,
},
} );
},
lockAttributesEditing( { select, context, args } ) {
const postId =
context?.postId || select( editorStore ).getCurrentPostId();
const postType =
context?.postType || select( editorStore ).getCurrentPostType();

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

Expand All @@ -64,8 +47,8 @@ export default {
// Check that the user has the capability to edit post meta.
const canUserEdit = select( coreDataStore ).canUserEditEntityRecord(
'postType',
postType,
postId
context?.postType,
context?.postId
);
if ( ! canUserEdit ) {
return true;
Expand Down

0 comments on commit 5fdbacb

Please sign in to comment.