Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Social_Links::adjust_block_contentprivateWC 1.0

Adjusts the block content. Returns css classes and styles compatible with email clients.

Method of the class: Social_Links{}

No Hooks.

Returns

Array. The adjusted block content.

Usage

// private - for code of main (parent) class only
$result = $this->adjust_block_content( $block_content, $parsed_block );
$block_content(string) (required)
The block content.
$parsed_block(array) (required)
The parsed block.

Social_Links::adjust_block_content() code WC 10.5.0

private function adjust_block_content( $block_content, $parsed_block ) {
	$block_content    = $this->adjust_style_attribute( $block_content );
	$block_attributes = wp_parse_args(
		$parsed_block['attrs'] ?? array(),
		array(
			'textAlign' => 'left',
			'style'     => array(),
		)
	);
	$html             = new \WP_HTML_Tag_Processor( $block_content );
	$classes          = 'wp-block-social-links';
	if ( $html->next_tag() ) {
		/** @var string $block_classes */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
		$block_classes = $html->get_attribute( 'class' ) ?? '';
		$classes      .= ' ' . $block_classes;
		// remove has-background to prevent double padding applied for wrapper and inner element.
		$block_classes = str_replace( 'has-background', '', $block_classes );
		// remove border related classes because we handle border on wrapping table cell.
		$block_classes = preg_replace( '/[a-z-]+-border-[a-z-]+/', '', $block_classes );
		/** @var string $block_classes */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
		$html->set_attribute( 'class', trim( $block_classes ) );
		$block_content = $html->get_updated_html();
	}

	$block_styles = $this->get_styles_from_block(
		array(
			'color'      => $block_attributes['style']['color'] ?? array(),
			'spacing'    => $block_attributes['style']['spacing'] ?? array(),
			'typography' => $block_attributes['style']['typography'] ?? array(),
			'border'     => $block_attributes['style']['border'] ?? array(),
		)
	);

	$styles = array(
		'min-width'      => '100%', // prevent Gmail App from shrinking the table on mobile devices.
		'vertical-align' => 'middle',
		'word-break'     => 'break-word',
	);

	$styles['text-align'] = 'left';
	if ( ! empty( $parsed_block['attrs']['textAlign'] ) ) { // in this case, textAlign needs to be one of 'left', 'center', 'right'.
		$styles['text-align'] = $parsed_block['attrs']['textAlign'];
	} elseif ( in_array( $parsed_block['attrs']['align'] ?? null, array( 'left', 'center', 'right' ), true ) ) {
		$styles['text-align'] = $parsed_block['attrs']['align'];
	}

	$compiled_styles = $this->compile_css( $block_styles['declarations'], $styles );
	$table_styles    = 'border-collapse: separate;'; // Needed because of border radius.

	return array(
		'table_styles'    => $table_styles,
		'classes'         => $classes,
		'compiled_styles' => $compiled_styles,
		'align'           => $styles['text-align'],
		'block_content'   => $block_content,
	);
}