WooCommerce Code Reference

Blocks_Width_Preprocessor
in package
implements Preprocessor

This class sets the width of the blocks based on the layout width or column count.

The final width in pixels is stored in the email_attrs array because we would like to avoid changing the original attributes.

Interfaces, Classes and Traits

Preprocessor
Interface Preprocessor

Table of Contents

preprocess()  : array<string|int, mixed>
Method to preprocess the content before rendering
add_missing_column_widths()  : array<string|int, mixed>
Add missing column widths
calculate_widths()  : array<string|int, mixed>
Recursively calculate block widths based on layout and parent padding.
convert_width_to_pixels()  : float
Convert width to pixels
get_block_horizontal_border()  : float
Sum a block's left and right border widths.
parse_number_from_string_with_pixels()  : float
Parse number from string with pixels

Methods

preprocess()

Method to preprocess the content before rendering

public preprocess(array<string|int, mixed> $parsed_blocks, array{contentSize: string} $layout, array{spacing: array{padding: array{bottom: string, left?: string, right?: string, top: string}, blockGap: string}} $styles) : array<string|int, mixed>
Parameters
$parsed_blocks : array<string|int, mixed>

Parsed blocks of the email.

$layout : array{contentSize: string}

Layout of the email.

$styles : array{spacing: array{padding: array{bottom: string, left?: string, right?: string, top: string}, blockGap: string}}

Styles of the email.

Return values
array<string|int, mixed>

add_missing_column_widths()

Add missing column widths

private add_missing_column_widths(array<string|int, mixed> $columns, float $columns_width[, array<string|int, mixed> $variables_map = array() ]) : array<string|int, mixed>
Parameters
$columns : array<string|int, mixed>

Columns.

$columns_width : float

Columns width.

$variables_map : array<string|int, mixed> = array()

CSS variable names to resolved pixel values.

Return values
array<string|int, mixed>

calculate_widths()

Recursively calculate block widths based on layout and parent padding.

private calculate_widths(array<string|int, mixed> $parsed_blocks, array<string|int, mixed> $layout, array<string|int, mixed> $styles[, array<string|int, mixed> $variables_map = array() ]) : array<string|int, mixed>

At the top level, root padding is zeroed out by preprocess() since it's distributed to individual blocks. Each block that received root padding from the Spacing_Preprocessor has its width reduced accordingly. For nested blocks, the parent block's own padding is subtracted as expected.

Parameters
$parsed_blocks : array<string|int, mixed>

Parsed blocks.

$layout : array<string|int, mixed>

Layout settings.

$styles : array<string|int, mixed>

Styles with padding from parent context.

$variables_map : array<string|int, mixed> = array()

CSS variable names to resolved pixel values.

Return values
array<string|int, mixed>

get_block_horizontal_border()

Sum a block's left and right border widths.

private get_block_horizontal_border(array<string|int, mixed> $block) : float

Supports both the shorthand border.width and the per-side border.left.width / border.right.width formats, matching how the columns block border is read elsewhere in this class.

Parameters
$block : array<string|int, mixed>

Parsed block.

Return values
floatCombined horizontal border width in pixels.