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

Quote_Preprocessor::apply_typography_to_childrenprivateWC 1.0

Apply typography styles to immediate paragraph children

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_typography_to_children( $blocks, $quote_typography, $styles ): array;
$blocks(array) (required)
The blocks to process.
$quote_typography(array) (required)
The typography styles from the quote block.
$styles(array) (required)
The styles from the theme.

Quote_Preprocessor::apply_typography_to_children() code WC 9.9.5

private function apply_typography_to_children( array $blocks, array $quote_typography, array $styles ): array {
	$default_typography = $styles['blocks']['core/quote']['typography'] ?? array();
	$merged_typography  = array_merge( $default_typography, $quote_typography );

	if ( empty( $merged_typography ) ) {
		return $blocks;
	}

	foreach ( $blocks as &$block ) {
		if ( 'core/paragraph' === $block['blockName'] ) {
			if ( ! isset( $block['attrs'] ) ) {
				$block['attrs'] = array();
			}
			if ( ! isset( $block['attrs']['style'] ) ) {
				$block['attrs']['style'] = array();
			}
			if ( ! isset( $block['attrs']['style']['typography'] ) ) {
				$block['attrs']['style']['typography'] = array();
			}

			// Merge typography styles, with block's own styles taking precedence.
			$block['attrs']['style']['typography'] = array_merge(
				$merged_typography,
				$block['attrs']['style']['typography']
			);
		}
	}

	return $blocks;
}