Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateChangeSummary::flatten_blockspublic staticWC 1.0

DFS-flatten a parse_blocks() into an ordered sequence of node descriptors (DFS pre-order: parent emitted before its children). Structural wrapper blocks (core/group, core/columns, …) are included in the output — the diff classifier inspects them via {@see self::STRUCTURAL_BLOCK_NAMES}. Null-name entries (raw HTML wrappers between blocks) are skipped.

Public so the RSM-143 selective-merge engine (WCEmailTemplateSelectiveApplier{}) can reuse this and {@see self::lcs_matches()} to align matched pairs without duplicating the algorithm. Internal namespace-bounded; not part of any external contract.

Method of the class: WCEmailTemplateChangeSummary{}

No Hooks.

Returns

Array. array{path:array<int|string>, parent_name:?string, name:string, inner_text:string}>

Usage

$result = WCEmailTemplateChangeSummary::flatten_blocks( $blocks, $path, ?string $parent_name ): array;
$blocks(array) (required)
.
$path(array<int|string>)
Current index path from root.
Default: array()
?string $parent_name
.
Default: null

WCEmailTemplateChangeSummary::flatten_blocks() code WC 10.9.1

public static function flatten_blocks( array $blocks, array $path = array(), ?string $parent_name = null ): array {
	$records = array();
	foreach ( $blocks as $idx => $block ) {
		if ( ! is_array( $block ) || null === ( $block['blockName'] ?? null ) ) {
			continue;
		}
		$name         = self::normalize_block_name( (string) $block['blockName'] );
		$current_path = array_merge( $path, array( $idx ) );

		$records[] = array(
			'path'        => $current_path,
			'parent_name' => $parent_name,
			'name'        => $name,
			'inner_text'  => self::clean_inner_text( (string) ( $block['innerHTML'] ?? '' ) ),
		);

		if ( ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) {
			$records = array_merge(
				$records,
				self::flatten_blocks( $block['innerBlocks'], $current_path, $name )
			);
		}
	}//end foreach
	return $records;
}