From 3f941e5a74ce931bf9f61cc4f375fbe00b59e85b Mon Sep 17 00:00:00 2001 From: Ricardo Artemio Morales Date: Thu, 12 Sep 2024 22:54:43 -0400 Subject: [PATCH 1/2] Add pattern context to block selection button --- .../block-tools/block-selection-button.js | 25 ++++++++++++++++--- .../src/hooks/use-bindings-attributes.js | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/block-selection-button.js b/packages/block-editor/src/components/block-tools/block-selection-button.js index 358f88cc2e7291..0294cd2d46a3b2 100644 --- a/packages/block-editor/src/components/block-tools/block-selection-button.js +++ b/packages/block-editor/src/components/block-tools/block-selection-button.js @@ -39,7 +39,10 @@ import { store as blockEditorStore } from '../../store'; import BlockDraggable from '../block-draggable'; import { useBlockElement } from '../block-list/use-block-props/use-block-refs'; import { unlock } from '../../lock-unlock'; -import { getBindingsValues } from '../../hooks/use-bindings-attributes'; +import { + getBindingsValues, + replacePatternOverrideDefaultBindings, +} from '../../hooks/use-bindings-attributes'; import BlockContext from '../block-context'; /** @@ -71,17 +74,33 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) { getNextBlockClientId, getPreviousBlockClientId, canMoveBlock, + getBlockParents, } = unlock( select( blockEditorStore ) ); const { getActiveBlockVariation, getBlockType } = select( blocksStore ); const index = getBlockIndex( clientId ); - const { name, attributes } = getBlock( clientId ); + const block = getBlock( clientId ); + const { name, attributes } = block; const blockType = getBlockType( name ); const orientation = getBlockListSettings( rootClientId )?.orientation; const match = getActiveBlockVariation( name, attributes ); - const blockBindings = attributes?.metadata?.bindings; + const blockBindings = replacePatternOverrideDefaultBindings( + name, + attributes?.metadata?.bindings + ); + + if ( blockBindings?.content?.source === 'core/pattern-overrides' ) { + const parents = getBlockParents( clientId ); + const parentBlock = + parents && parents.length > 0 + ? getBlock( parents[ 0 ] ) + : null; + blockContext[ 'pattern/overrides' ] = + parentBlock?.attributes?.content; + } + const boundAttributes = getBindingsValues( blockBindings, name, diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index ee65c13ac853cd..387db8a3ed05a6 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -45,7 +45,7 @@ const DEFAULT_ATTRIBUTE = '__default'; * * @return {Object} The bindings with default replaced for pattern overrides. */ -function replacePatternOverrideDefaultBindings( blockName, bindings ) { +export function replacePatternOverrideDefaultBindings( blockName, bindings ) { // The `__default` binding currently only works for pattern overrides. if ( bindings?.[ DEFAULT_ATTRIBUTE ]?.source === 'core/pattern-overrides' From b0c789282e8c43240edd089d5661d1146cd211a0 Mon Sep 17 00:00:00 2001 From: Ricardo Artemio Morales Date: Thu, 12 Sep 2024 22:57:15 -0400 Subject: [PATCH 2/2] Revise paragraph logic to use pattern override content --- packages/block-library/src/paragraph/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index 715fb35ec05ab1..e87bf6cacab56e 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -30,18 +30,21 @@ export const settings = { __experimentalLabel( attributes, { context } ) { const customName = attributes?.metadata?.name; - if ( context === 'list-view' && customName ) { - return customName; - } - if ( context === 'accessibility' ) { - if ( customName ) { + if ( + customName && + ! attributes?.metadata?.bindings?.source === 'pattern/overrides' + ) { return customName; } const { content } = attributes; return ! content || content.length === 0 ? __( 'Empty' ) : content; } + + if ( context === 'list-view' && customName ) { + return customName; + } }, transforms, deprecated,