Skip to content

Commit

Permalink
Block Bindings: Always prioritize using context in post meta source l…
Browse files Browse the repository at this point in the history
…ogic (#65449)

* Use `getCurrentPostType`

* Change conditional to prioritize context

Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
  • Loading branch information
3 people authored Sep 18, 2024
1 parent e40612b commit 6a6b3a3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/editor/src/bindings/post-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import { unlock } from '../lock-unlock';

function getMetadata( registry, context, registeredFields ) {
let metaFields = {};
const { type } = registry.select( editorStore ).getCurrentPost();
const type = registry.select( editorStore ).getCurrentPostType();
const { getEditedEntityRecord } = registry.select( coreDataStore );

if ( type === 'wp_template' ) {
if ( context?.postType && context?.postId ) {
metaFields = getEditedEntityRecord(
'postType',
context?.postType,
context?.postId
).meta;
} else if ( type === 'wp_template' ) {
// Populate the `metaFields` object with the default values.
Object.entries( registeredFields || {} ).forEach(
( [ key, props ] ) => {
Expand All @@ -23,12 +29,6 @@ function getMetadata( registry, context, registeredFields ) {
}
}
);
} else {
metaFields = getEditedEntityRecord(
'postType',
context?.postType,
context?.postId
).meta;
}

return metaFields;
Expand Down

0 comments on commit 6a6b3a3

Please sign in to comment.