diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 0708ee342593e3..c2f30d95dd2116 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -42,7 +42,7 @@ Reuse this design across your site. ([Source](https://github.com/WordPress/guten - **Name:** core/block - **Category:** reusable - **Supports:** ~~customClassName~~, ~~html~~, ~~inserter~~, ~~renaming~~ -- **Attributes:** overrides, ref +- **Attributes:** content, ref ## Button diff --git a/packages/block-library/src/block/block.json b/packages/block-library/src/block/block.json index 7eac2b705ba1f2..ac0790abd089f5 100644 --- a/packages/block-library/src/block/block.json +++ b/packages/block-library/src/block/block.json @@ -11,7 +11,7 @@ "ref": { "type": "number" }, - "overrides": { + "content": { "type": "object" } }, diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index c940f36e1a8b86..6f9a61dc14b02c 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -108,11 +108,11 @@ const PATCH_OPERATIONS = { * @typedef {RemovePatch | ReplacePatch} OverridePatch */ -function applyInitialOverrides( blocks, overrides = {}, defaultValues ) { +function applyInitialOverrides( blocks, content = {}, defaultValues ) { return blocks.map( ( block ) => { const innerBlocks = applyInitialOverrides( block.innerBlocks, - overrides, + content, defaultValues ); const blockId = block.attributes.metadata?.id; @@ -125,7 +125,7 @@ function applyInitialOverrides( blocks, overrides = {}, defaultValues ) { defaultValues[ blockId ][ attributeKey ] = block.attributes[ attributeKey ]; /** @type {OverridePatch} */ - const overrideAttribute = overrides[ blockId ]?.[ attributeKey ]; + const overrideAttribute = content[ blockId ]?.[ attributeKey ]; if ( ! overrideAttribute ) { continue; } @@ -145,10 +145,10 @@ function applyInitialOverrides( blocks, overrides = {}, defaultValues ) { function getOverridesFromBlocks( blocks, defaultValues ) { /** @type {Record>} */ - const overrides = {}; + const content = {}; for ( const block of blocks ) { Object.assign( - overrides, + content, getOverridesFromBlocks( block.innerBlocks, defaultValues ) ); /** @type {string} */ @@ -160,7 +160,7 @@ function getOverridesFromBlocks( blocks, defaultValues ) { block.attributes[ attributeKey ] !== defaultValues[ blockId ][ attributeKey ] ) { - overrides[ blockId ] ??= {}; + content[ blockId ] ??= {}; /** * Create a patch operation for the binding attribute. * We use a tuple here to minimize the size of the serialized data. @@ -168,12 +168,12 @@ function getOverridesFromBlocks( blocks, defaultValues ) { */ if ( block.attributes[ attributeKey ] === undefined ) { /** @type {RemovePatch} */ - overrides[ blockId ][ attributeKey ] = [ + content[ blockId ][ attributeKey ] = [ PATCH_OPERATIONS.Remove, ]; } else { /** @type {ReplacePatch} */ - overrides[ blockId ][ attributeKey ] = [ + content[ blockId ][ attributeKey ] = [ PATCH_OPERATIONS.Replace, block.attributes[ attributeKey ], ]; @@ -181,7 +181,7 @@ function getOverridesFromBlocks( blocks, defaultValues ) { } } } - return Object.keys( overrides ).length > 0 ? overrides : undefined; + return Object.keys( content ).length > 0 ? content : undefined; } function setBlockEditMode( setEditMode, blocks, mode ) { @@ -202,7 +202,7 @@ function getHasOverridableBlocks( blocks ) { export default function ReusableBlockEdit( { name, - attributes: { ref, overrides }, + attributes: { ref, content }, __unstableParentLayout: parentLayout, clientId: patternClientId, setAttributes, @@ -215,7 +215,7 @@ export default function ReusableBlockEdit( { ref ); const isMissing = hasResolved && ! record; - const initialOverrides = useRef( overrides ); + const initialOverrides = useRef( content ); const defaultValuesRef = useRef( {} ); const { @@ -338,7 +338,7 @@ export default function ReusableBlockEdit( { prevBlocks = blocks; syncDerivedUpdates( () => { setAttributes( { - overrides: getOverridesFromBlocks( + content: getOverridesFromBlocks( blocks, defaultValuesRef.current ), @@ -354,7 +354,7 @@ export default function ReusableBlockEdit( { }; const resetOverrides = () => { - if ( overrides ) { + if ( content ) { replaceInnerBlocks( patternClientId, initialBlocks ); } }; @@ -405,7 +405,7 @@ export default function ReusableBlockEdit( { { __( 'Reset' ) } diff --git a/packages/block-library/src/block/index.php b/packages/block-library/src/block/index.php index 444001fa498595..dd94e94ecaeb51 100644 --- a/packages/block-library/src/block/index.php +++ b/packages/block-library/src/block/index.php @@ -46,7 +46,7 @@ function render_block_core_block( $attributes ) { $content = $wp_embed->run_shortcode( $reusable_block->post_content ); $content = $wp_embed->autoembed( $content ); - $has_pattern_overrides = isset( $attributes['overrides'] ); + $has_pattern_overrides = isset( $attributes['content'] ); /** * We set the `pattern/overrides` context through the `render_block_context` @@ -55,7 +55,7 @@ function render_block_core_block( $attributes ) { */ if ( $has_pattern_overrides ) { $filter_block_context = static function ( $context ) use ( $attributes ) { - $context['pattern/overrides'] = $attributes['overrides']; + $context['pattern/overrides'] = $attributes['content']; return $context; }; add_filter( 'render_block_context', $filter_block_context, 1 ); diff --git a/test/e2e/specs/editor/various/pattern-overrides.spec.js b/test/e2e/specs/editor/various/pattern-overrides.spec.js index 417827a9071581..34998a1fd339b7 100644 --- a/test/e2e/specs/editor/various/pattern-overrides.spec.js +++ b/test/e2e/specs/editor/various/pattern-overrides.spec.js @@ -170,7 +170,7 @@ test.describe( 'Pattern Overrides', () => { name: 'core/block', attributes: { ref: patternId, - overrides: { + content: { [ editableParagraphId ]: { content: [ 1, 'I would word it this way' ], }, @@ -181,7 +181,7 @@ test.describe( 'Pattern Overrides', () => { name: 'core/block', attributes: { ref: patternId, - overrides: { + content: { [ editableParagraphId ]: { content: [ 1, 'This one is different' ], }, @@ -305,7 +305,7 @@ test.describe( 'Pattern Overrides', () => { name: 'core/block', attributes: { ref: id, - overrides: { + content: { [ buttonId ]: { linkTarget: [ 0 ], },