Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Gallery::build_gallery_row_table
Build a single gallery row as a separate table (following tiled gallery pattern).
Method of the class: Gallery{}
No Hooks.
Returns
String. Row table HTML.
Usage
// private - for code of main (parent) class only $result = $this->build_gallery_row_table( $row_images, $total_columns, $cell_padding ): string;
- $row_images(array) (required)
- Images for this row.
- $total_columns(int) (required)
- Total number of columns.
- $cell_padding(int) (required)
- Cell padding.
Gallery::build_gallery_row_table() Gallery::build gallery row table code WC 10.5.0
private function build_gallery_row_table( array $row_images, int $total_columns, int $cell_padding ): string {
$images_in_row = count( $row_images );
$row_cells = '';
// If there is exactly one image, span full width; otherwise distribute width evenly across the images in this row.
if ( 1 === $images_in_row ) {
$cell_attrs = array(
'style' => sprintf( 'width: %s; padding: %dpx; vertical-align: top; text-align: center;', Html_Processing_Helper::sanitize_css_value( '100%' ), $cell_padding ),
'valign' => 'top',
'colspan' => $total_columns,
);
$row_cells .= Table_Wrapper_Helper::render_table_cell( $row_images[0], $cell_attrs );
} else {
// Evenly distribute available width among the images in this row.
$cell_width_percent = 100 / $images_in_row;
foreach ( $row_images as $image_html ) {
$cell_attrs = array(
'style' => sprintf(
'width: %s; padding: %dpx; vertical-align: top; text-align: center;',
Html_Processing_Helper::sanitize_css_value( sprintf( '%.2f%%', $cell_width_percent ) ),
$cell_padding
),
'valign' => 'top',
);
$row_cells .= Table_Wrapper_Helper::render_table_cell( $image_html, $cell_attrs );
}
}
// Create a separate table for this row (following tiled gallery pattern).
return sprintf(
'<table role="presentation" style="width: %s; border-collapse: collapse; table-layout: fixed;"><tr>%s</tr></table>',
Html_Processing_Helper::sanitize_css_value( '100%' ),
$row_cells
);
}