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

Gallery::build_email_layoutprivateWC 1.0

Build the email-friendly layout for gallery blocks.

Method of the class: Gallery{}

No Hooks.

Returns

String. Rendered HTML.

Usage

// private - for code of main (parent) class only
$result = $this->build_email_layout( $gallery_images, $parsed_block, $block_content, $rendering_context ): string;
$gallery_images(array) (required)
Array of image HTML strings.
$parsed_block(array) (required)
Full parsed block data.
$block_content(string) (required)
Original block content.
$rendering_context(Rendering_Context) (required)
Rendering context.

Gallery::build_email_layout() code WC 10.5.0

private function build_email_layout( array $gallery_images, array $parsed_block, string $block_content, 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( 'figure', 'class' ) ?? '';

	// Get gallery attributes.
	$block_attrs = $parsed_block['attrs'] ?? array();
	$columns     = $this->get_columns_from_attributes( $block_attrs );

	// Extract gallery-level caption from the original block content.
	$gallery_caption = $this->extract_gallery_caption( $block_content );

	// Get block styles using the Styles_Helper.
	$block_styles = Styles_Helper::get_block_styles( $block_attrs, $rendering_context, array( 'padding', 'border', 'background', 'background-color', 'color' ) );
	$block_styles = Styles_Helper::extend_block_styles(
		$block_styles,
		array(
			'width'           => '100%',
			'border-collapse' => 'collapse',
			'text-align'      => 'left',
		)
	);

	// Apply class and style attributes to the wrapper table.
	$table_attrs = array(
		'class' => 'email-block-gallery ' . Html_Processing_Helper::clean_css_classes( $original_wrapper_classname ),
		'style' => $block_styles['css'],
		'align' => 'left',
		'width' => '100%',
	);

	// Add email width to cell attributes if available.
	$cell_attrs = array();
	if ( isset( $parsed_block['email_attrs']['width'] ) ) {
		$cell_attrs['width'] = $parsed_block['email_attrs']['width'];
	}

	// Build the gallery rows with proper table structure.
	$gallery_content = $this->build_gallery_table( $gallery_images, $columns );

	// Add gallery caption if it exists.
	if ( ! empty( $gallery_caption ) ) {
		$gallery_content .= '<br><div class="blocks-gallery-caption wp-element-caption" style="font-size: 13px; line-height: 1.0; text-align: center;">' . $gallery_caption . '</div>';
	}

	// Use Table_Wrapper_Helper for the main container (following tiled gallery pattern).
	return Table_Wrapper_Helper::render_table_wrapper( $gallery_content, $table_attrs, $cell_attrs );
}