Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Use getValuesInBatch in pattern overrides
  • Loading branch information
SantosGuillamot committed Jul 5, 2024
commit 5c3221f46bfaed90bd79c5c050a8d8870a0a6bf8
22 changes: 22 additions & 0 deletions packages/editor/src/bindings/pattern-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ export default {

return overridableValue === '' ? undefined : overridableValue;
},
// When `getValuesInBatch` is defined, this is not running.
// Keeping it here to show the different possibilities.
getValuesInBatch( { registry, clientId, context, sourceBindings } ) {
const patternOverridesContent = context[ 'pattern/overrides' ];
if ( ! patternOverridesContent ) {
return {};
}

const { getBlockAttributes } = registry.select( blockEditorStore );
const currentBlockAttributes = getBlockAttributes( clientId );

const overridesValues = {};
for ( const attributeName of Object.keys( sourceBindings ) ) {
const overridableValue =
patternOverridesContent?.[
currentBlockAttributes?.metadata?.name
]?.[ attributeName ];
overridesValues[ attributeName ] =
overridableValue === '' ? undefined : overridableValue;
}
return overridesValues;
},
setValuesInBatch( { registry, clientId, sourceBindings } ) {
const { getBlockAttributes, getBlockParentsByBlockName, getBlocks } =
registry.select( blockEditorStore );
Expand Down