Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors

Quote_Preprocessor::apply_alignment_to_childrenprivateWC 1.0

Apply text alignment to child blocks that don't have their own text alignment set

Method of the class: Quote_Preprocessor{}

No Hooks.

Returns

Array. The processed blocks.

Usage

// private - for code of main (parent) class only
$result = $this->apply_alignment_to_children( $blocks, ?string $text_align ): array;
$blocks(array) (required)
The blocks to process.
?string $text_align
.
Default: null

Quote_Preprocessor::apply_alignment_to_children() code WC 9.9.5

private function apply_alignment_to_children( array $blocks, ?string $text_align = null ): array {
	if ( ! $text_align ) {
		return $blocks;
	}

	foreach ( $blocks as &$block ) {
		// Only apply alignment if the block doesn't already have one set.
		if ( ! isset( $block['attrs']['textAlign'] ) && ! isset( $block['attrs']['align'] ) ) {
			if ( ! isset( $block['attrs'] ) ) {
				$block['attrs'] = array();
			}
			$block['attrs']['textAlign'] = $text_align;
		}

		if ( isset( $block['innerBlocks'] ) ) {
			$block['innerBlocks'] = $this->apply_alignment_to_children( $block['innerBlocks'], $block['attrs']['textAlign'] ?? $block['attrs']['align'] );
		}
	}

	return $blocks;
}