Skip to content

Commit

Permalink
Add pattern context to block selection button
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiomorales committed Sep 13, 2024
1 parent b7c326c commit 3f941e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 3f941e5

Please sign in to comment.