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
- parse_number_from_string_with_pixels() : float
- Parse number from string with pixels
- resolve_preset_value() : string
- Resolve a CSS value that may contain a preset variable reference.
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> —convert_width_to_pixels()
Convert width to pixels
private
convert_width_to_pixels(string $current_width, float $layout_width) : float
Parameters
- $current_width : string
-
Current width.
- $layout_width : float
-
Layout width.
Return values
float —parse_number_from_string_with_pixels()
Parse number from string with pixels
private
parse_number_from_string_with_pixels(string $value) : float
Parameters
- $value : string
-
Value with pixels.
Return values
float —resolve_preset_value()
Resolve a CSS value that may contain a preset variable reference.
private
resolve_preset_value(string $value, array<string|int, mixed> $variables_map) : string
Block attributes store padding as preset references like "var:preset|spacing|20" which resolve to actual pixel values (e.g. "8px"). This method converts the reference to its resolved value using the variables map passed through styles.
Parameters
- $value : string
-
The CSS value, possibly a preset reference.
- $variables_map : array<string|int, mixed>
-
Map of CSS variable names to resolved values.
