Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateSelectiveApplier::replace_recursive │ private static │ WC 1.0

Recursive worker for {@see self::replace_block_content_at_path()}.

Method of the class: WCEmailTemplateSelectiveApplier{}

No Hooks.

Returns

array<int|string,. array<string, mixed>>

Usage

$result = WCEmailTemplateSelectiveApplier::replace_recursive( $blocks, $path, $depth, $source_block, $copy_attrs ): array;
$blocks(array) (required)
.
$path(array<int|string>) (required)
Path indices.
$depth(int) (required)
Current depth.
$source_block(array<string, mixed>) (required)
Source block to copy content from.
$copy_attrs(true|false)
Whether to take the source block's attrs as well.
Default: false

WCEmailTemplateSelectiveApplier::replace_recursive() code WC 11.3.0

private static function replace_recursive( array $blocks, array $path, int $depth, array $source_block, bool $copy_attrs = false ): array {
	$idx = (int) $path[ $depth ];
	if ( ! isset( $blocks[ $idx ] ) ) {
		return $blocks;
	}

	if ( count( $path ) - 1 === $depth ) {
		// Callers keep blocks holding other blocks away from here: this
		// replaces `innerBlocks` wholesale, which would discard whatever the
		// merchant had inside.
		$blocks[ $idx ]['innerHTML']    = $source_block['innerHTML'] ?? '';
		$blocks[ $idx ]['innerContent'] = $source_block['innerContent'] ?? array();
		$blocks[ $idx ]['innerBlocks']  = $source_block['innerBlocks'] ?? array();
		if ( $copy_attrs ) {
			$blocks[ $idx ]['attrs'] = $source_block['attrs'] ?? array();
		}
		return $blocks;
	}

	$inner                         = $blocks[ $idx ]['innerBlocks'] ?? array();
	$blocks[ $idx ]['innerBlocks'] = self::replace_recursive( is_array( $inner ) ? $inner : array(), $path, $depth + 1, $source_block, $copy_attrs );
	return $blocks;
}