Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Cover::build_email_layout
Build the email-friendly layout for cover blocks.
Method of the class: Cover{}
No Hooks.
Returns
String. Rendered HTML.
Usage
// private - for code of main (parent) class only $result = $this->build_email_layout( $inner_content, $block_attrs, $block_content, $background_image, $rendering_context ): string;
- $inner_content(string) (required)
- Inner content.
- $block_attrs(array) (required)
- Block attributes.
- $block_content(string) (required)
- Original block content.
- $background_image(string) (required)
- Background image URL.
- $rendering_context(Rendering_Context) (required)
- Rendering context.
Cover::build_email_layout() Cover::build email layout code WC 10.5.0
private function build_email_layout( string $inner_content, array $block_attrs, string $block_content, string $background_image, Rendering_Context $rendering_context ): string {
// Get original wrapper classes from block content.
$original_wrapper_classname = ( new Dom_Document_Helper( $block_content ) )->get_attribute_value_by_tag_name( 'div', 'class' ) ?? '';
// Get background color information.
$background_color = $this->get_background_color( $block_attrs, $rendering_context );
// Get block styles using the Styles_Helper.
$block_styles = Styles_Helper::get_block_styles( $block_attrs, $rendering_context, array( 'padding', 'border', 'background-color' ) );
$default_styles = array(
'width' => '100%',
'border-collapse' => 'collapse',
'text-align' => 'center',
);
// Add minimum height (use specified value or default).
$min_height = $this->get_minimum_height( $block_attrs );
$default_styles['min-height'] = ! empty( $min_height ) ? $min_height : '430px';
$block_styles = Styles_Helper::extend_block_styles(
$block_styles,
$default_styles
);
// Add background image to table styles if present.
if ( ! empty( $background_image ) ) {
$block_styles = Styles_Helper::extend_block_styles(
$block_styles,
array(
'background-image' => 'url("' . esc_url( $background_image ) . '")',
'background-size' => 'cover',
'background-position' => 'center',
'background-repeat' => 'no-repeat',
)
);
} elseif ( ! empty( $background_color ) ) {
// If no background image but there's a background color, use it.
$block_styles = Styles_Helper::extend_block_styles(
$block_styles,
array(
'background-color' => $background_color,
)
);
}
// Apply class and style attributes to the wrapper table.
$table_attrs = array(
'class' => 'email-block-cover ' . esc_attr( $original_wrapper_classname ),
'style' => $block_styles['css'],
'align' => 'center',
'width' => '100%',
);
// Build the cover content without background (background is now on the table).
$cover_content = $this->build_cover_content( $inner_content );
// Build individual table cell.
$cell_attrs = array(
'valign' => 'middle',
'align' => 'center',
);
$cell = Table_Wrapper_Helper::render_table_cell( $cover_content, $cell_attrs );
// Use render_cell = false to avoid wrapping in an extra <td>.
return Table_Wrapper_Helper::render_table_wrapper( $cell, $table_attrs, array(), array(), false );
}