Skip to content

Add nested block structures possibility with wp_register_block_types_from_metadata_collection #71036

@Lovor01

Description

@Lovor01

It is very convenient and tidy to keep inner blocks source code inside parent blocks. It keeps track of parent-child relationship and the whole structure when having many blocks in single plugin is better, since it is organized in a tree instead of being flat and has less entries in top level structure. I had so far positive experience developing with such organization and wordpress-scripts compilation works fine.

Example of folder structure (each folder contains single block):

slider
|__ slide
event-manager
|__ event
tabs-block
|__ tabs-header
|__ tabs-card

However, with new introduced wp_register_block_types_from_metadata_collection which speeds up block registration and therefore editor initialization, I see this warning: PHP Deprecated: dirname(): Passing null to parameter #1 ($path) of type string is deprecated .... When I flatten the block structure, meaning that all nested block folders are moved to same level as parent blocks, error disappears.

Proposed solution is to rewrite @wordpress/scripts code for --blocks-manifest switch to enable nested structure (if needed) and rewrite wp_register_block_types_from_metadata_collection to load blocks from nested folders without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs DecisionNeeds a decision to be actionable or relevant[Feature] Block APIAPI that allows to express the block paradigm.[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions