Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks
Product_Image::apply_email_wrapper
Apply email-compatible table wrapper (similar to Image renderer).
Method of the class: Product_Image{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->apply_email_wrapper( $image_html, $parsed_block, $rendering_context ): string;
- $image_html(string) (required)
- Image HTML.
- $parsed_block(array) (required)
- Parsed block.
- $rendering_context(Rendering_Context) (required)
- Rendering context.
Product_Image::apply_email_wrapper() Product Image::apply email wrapper code WC 10.8.1
private function apply_email_wrapper( string $image_html, array $parsed_block, Rendering_Context $rendering_context ): string {
$width = $parsed_block['attrs']['width'] ?? '';
$align = $parsed_block['attrs']['align'] ?? '';
$is_full = 'full' === $align;
$wrapper_width = $is_full ? '100%' : ( ( $width && '100%' !== $width ) ? $width : 'auto' );
$image_height = $this->extract_image_height( $image_html ) . 'px';
// Map block alignment to valid HTML/CSS alignment values.
// "full" is not a valid text-align or table align value.
$css_align = $is_full ? 'center' : ( $align ? $align : 'left' );
$wrapper_styles = array(
'border-collapse' => 'separate',
'width' => $wrapper_width,
);
$cell_styles = array(
'overflow' => 'hidden',
'vertical-align' => 'top',
);
// Apply padding from block styles (e.g., padding-top, padding-bottom).
$padding_styles = Styles_Helper::get_block_styles( $parsed_block['attrs'] ?? array(), $rendering_context, array( 'spacing' ) );
if ( ! empty( $padding_styles['declarations'] ) ) {
$cell_styles = array_merge( $cell_styles, $padding_styles['declarations'] );
}
$cell_styles['text-align'] = $css_align;
$outer_table_attrs = array(
'style' => \WP_Style_Engine::compile_css(
array(
'border-collapse' => 'collapse',
'border-spacing' => '0px',
'width' => '100%',
'height' => $image_height,
),
''
),
'width' => '100%',
);
$outer_cell_attrs = array(
'align' => $css_align,
);
$inner_table_attrs = array(
'style' => \WP_Style_Engine::compile_css( $wrapper_styles, '' ),
'width' => $wrapper_width,
'height' => $image_height,
);
$inner_cell_attrs = array(
'style' => \WP_Style_Engine::compile_css( $cell_styles, '' ),
);
$inner_content = Table_Wrapper_Helper::render_table_wrapper( $image_html, $inner_table_attrs, $inner_cell_attrs );
return Table_Wrapper_Helper::render_table_wrapper( $inner_content, $outer_table_attrs, $outer_cell_attrs );
}