Template_Utils::flatten_blocks( TECCommonEditorFull_Sitearray<array> $blocks )
Returns an array containing the references of the passed blocks and their inner blocks.
Contents
When we return we are replacing/overwriting $blocks with $all_blocks so we pass-by-reference. If we don’t pass-by-reference the non-event blocks get lost (ex: header and footer)
Parameters
- $blocks
-
(<span class="TECCommonEditorFull_Sitearray<array>">TECCommonEditorFull_Sitearray<array>) (Required) Array of parsed block objects.
Return
(TECCommonEditorFull_Sitearray<array<string,mixed>>) Block references to the passed blocks and their inner blocks.
Source
File: src/Common/Editor/Full_Site/Template_Utils.php
public static function flatten_blocks( &$blocks ) { $all_blocks = []; $queue = []; foreach ( $blocks as &$block ) { $queue[] = &$block; } $queue_count = count( $queue ); while ( $queue_count > 0 ) { $block = &$queue[0]; array_shift( $queue ); $all_blocks[] = &$block; if ( ! empty( $block['innerBlocks'] ) ) { foreach ( $block['innerBlocks'] as &$inner_block ) { $queue[] = &$inner_block; } } $queue_count = count( $queue ); } return $all_blocks; }
Changelog
Version | Description |
---|---|
4.14.18 | Introduced. |