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

Column::get_block_wrapperprivateWC 1.0

Based on MJML <mj-column>

Метод класса: Column{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_block_wrapper( $block_content, $parsed_block, $rendering_context ): string;
$block_content(строка) (обязательный)
Block content.
$parsed_block(массив) (обязательный)
Parsed block.
$rendering_context(Rendering_Context) (обязательный)
Rendering context.

Код Column::get_block_wrapper() WC 10.7.0

private function get_block_wrapper( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
	$original_wrapper_classname = ( new Dom_Document_Helper( $block_content ) )->get_attribute_value_by_tag_name( 'div', 'class' ) ?? '';
	$block_attributes           = wp_parse_args(
		$parsed_block['attrs'] ?? array(),
		array(
			'verticalAlignment' => 'stretch',
			'width'             => $rendering_context->get_layout_width_without_padding(),
			'style'             => array(),
		)
	);

	// The default column alignment is `stretch to fill` which means that we need to set the background color to the main cell
	// to create a feeling of a stretched column. This also needs to apply to CSS classnames which can also apply styles.
	$is_stretched = empty( $block_attributes['verticalAlignment'] ) || 'stretch' === $block_attributes['verticalAlignment'];

	$padding_styles = Styles_Helper::get_block_styles( $block_attributes, $rendering_context, array( 'padding' ) );
	$padding_styles = Styles_Helper::extend_block_styles( $padding_styles, array( 'text-align' => 'left' ) );

	$cell_styles = Styles_Helper::get_block_styles( $block_attributes, $rendering_context, array( 'border', 'background', 'background-color', 'color' ) );
	$cell_styles = Styles_Helper::extend_block_styles(
		$cell_styles,
		array_filter(
			array(
				'background-size' => ! empty( $cell_styles['background-image'] ) && empty( $cell_styles['background-size'] ) ? 'cover' : null,
			)
		)
	);

	$wrapper_classname = 'block wp-block-column email-block-column';
	$content_classname = 'email-block-column-content';
	$wrapper_styles    = Styles_Helper::extend_block_styles(
		Styles_Helper::$empty_block_styles,
		array( 'vertical-align' => $is_stretched ? 'top' : $block_attributes['verticalAlignment'] ),
	);
	$content_styles    = Styles_Helper::extend_block_styles( Styles_Helper::$empty_block_styles, array( 'vertical-align' => 'top' ) );

	if ( $is_stretched ) {
		$wrapper_classname .= ' ' . $original_wrapper_classname;
		$wrapper_styles     = Styles_Helper::extend_block_styles( $wrapper_styles, $cell_styles['declarations'] );
	} else {
		$content_classname .= ' ' . $original_wrapper_classname;
		$content_styles     = Styles_Helper::extend_block_styles( $content_styles, $cell_styles['declarations'] );
	}

	// Create the inner table using the helper.
	$inner_table_attrs = array(
		'class' => $content_classname,
		'style' => $content_styles['css'],
		'width' => '100%',
	);

	$inner_cell_attrs = array(
		'align' => 'left',
		'style' => $padding_styles['css'],
	);

	$inner_table = Table_Wrapper_Helper::render_table_wrapper( '{column_content}', $inner_table_attrs, $inner_cell_attrs );

	// Apply padding-left from email_attrs (set by Spacing_Preprocessor for columns blockGap).
	$padding_left = $parsed_block['email_attrs']['padding-left'] ?? null;
	if ( $padding_left ) {
		$gap_padding_styles = wp_style_engine_get_styles( array( 'spacing' => array( 'padding' => array( 'left' => $padding_left ) ) ) );
		$wrapper_styles     = Styles_Helper::extend_block_styles( $wrapper_styles, $gap_padding_styles['declarations'] ?? array() );
	}

	// Create the outer td element (since this is meant to be used within a columns structure).
	$wrapper_cell_attrs = array(
		'class' => $wrapper_classname,
		'style' => $wrapper_styles['css'],
		'width' => Styles_Helper::parse_value( $block_attributes['width'] ),
	);

	return Table_Wrapper_Helper::render_table_cell( $inner_table, $wrapper_cell_attrs );
}