Skip to content
Draft
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
Inserter: Allow parent/ancestor filtering by block variation name
  • Loading branch information
ockham committed Dec 8, 2025
commit 73fbd701926ead92174182d5229d6bbf7a148676
19 changes: 18 additions & 1 deletion packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import {
getActiveBlockVariation,
getBlockType,
getBlockTypes,
getBlockVariations,
Expand Down Expand Up @@ -1650,10 +1651,26 @@ const isBlockVisibleInTheInserter = (
let current = rootClientId;
let hasParent = false;
do {
if ( parents.includes( getBlockName( state, current ) ) ) {
const ancestorBlockName = getBlockName( state, current );
if ( parents.includes( ancestorBlockName ) ) {
hasParent = true;
break;
}
const ancestorAttributes = getBlockAttributes( state, current );

const variation = getActiveBlockVariation(
ancestorBlockName,
ancestorAttributes,
'inserter'
);

if ( variation ) {
// TODO: Compare block variation name to parent/ancestor list.
// Problem: For template parts that have been persisted to the DB,
// variation.name is prefixed with `instance_` (e.g. `instance_header`).
Comment on lines +1668 to +1670
Copy link
Copy Markdown
Contributor Author

@ockham ockham Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

'name' => 'instance_' . sanitize_title( $template_part->slug ),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More context and rationale: #49500

console.log( variation );
}

current = state.blocks.parents.get( current );
} while ( current );

Expand Down
Loading