From 702826e9f13385b6af1fb62330cbd423b10b35ba Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 31 Jan 2024 18:55:15 +1300 Subject: [PATCH] Patterns" Update the bindings attribs of blocks added during experimental phase (#58483) * Update the bindings attribs of blocks added during pattern overrides experimental phase * Update all the binding attributes * Minor optimization / code quality change --------- Co-authored-by: Daniel Richards --- .../src/api/parser/convert-legacy-block.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/blocks/src/api/parser/convert-legacy-block.js b/packages/blocks/src/api/parser/convert-legacy-block.js index c993d450099912..6d6a37a0233bce 100644 --- a/packages/blocks/src/api/parser/convert-legacy-block.js +++ b/packages/blocks/src/api/parser/convert-legacy-block.js @@ -77,5 +77,33 @@ export function convertLegacyBlockNameAndAttributes( name, attributes ) { newAttributes.legacy = true; } + // Convert pattern overrides added during experimental phase. + // Only four blocks were supported initially. + // These checks can be removed in WordPress 6.6. + if ( + newAttributes.metadata?.bindings && + ( name === 'core/paragraph' || + name === 'core/heading' || + name === 'core/image' || + name === 'core/button' ) + ) { + const bindings = [ + 'content', + 'url', + 'title', + 'alt', + 'text', + 'linkTarget', + ]; + bindings.forEach( ( binding ) => { + if ( + newAttributes.metadata.bindings[ binding ]?.source?.name === + 'pattern_attributes' + ) { + newAttributes.metadata.bindings[ binding ].source = + 'core/pattern-overrides'; + } + } ); + } return [ name, newAttributes ]; }