Automattic\WooCommerce\Blocks\Templates

SingleProductTemplateCompatibility::group_blocks()private staticWC 1.0

Group blocks in this way: B1 + TP1 + B2 + B3 + B4 + TP2 + B5 (B = Block, TP = Template Part) becomes: [[B1], [TP1], [B2, B3, B4], [TP2], [B5]]

Метод класса: SingleProductTemplateCompatibility{}

Хуков нет.

Возвращает

Массив. Array of blocks grouped by template part.

Использование

$result = SingleProductTemplateCompatibility::group_blocks( $parsed_blocks );
$parsed_blocks(массив) (обязательный)
Array of parsed block objects.

Код SingleProductTemplateCompatibility::group_blocks() WC 9.1.2

private static function group_blocks( $parsed_blocks ) {
	return array_reduce(
		$parsed_blocks,
		function ( array $carry, array $block ) {
			if ( 'core/template-part' === $block['blockName'] ) {
				$carry[] = array( $block );
				return $carry;
			}
			$last_element_index = count( $carry ) - 1;
			if ( isset( $carry[ $last_element_index ][0]['blockName'] ) && 'core/template-part' !== $carry[ $last_element_index ][0]['blockName'] ) {
				$carry[ $last_element_index ][] = $block;
				return $carry;
			}
			$carry[] = array( $block );
			return $carry;
		},
		array()
	);
}