Image
extends Abstract_Block_Renderer
in package
Renders an image block.
Table of Contents
- render() : string
- Render the block.
- add_spacer() : string
- Add a spacer around the block.
- compile_css() : string
- Compile objects containing CSS properties to a string.
- get_styles_from_block() : array<string|int, mixed>
- Wrapper for wp_style_engine_get_styles which ensures all values are returned.
- render_content() : string
- Renders the block content.
- add_image_size_when_missing() : array<string|int, mixed>
- When the width is not set, it's important to get it for the image to be displayed correctly
- add_style_to_element() : string
- Add style to the element.
- addImageDimensions() : string
- Settings width and height attributes for images is important for MS Outlook.
- apply_image_border_style() : string
- Apply border style to the image.
- apply_rounded_style() : string
- Apply rounded style to the image.
- cleanup_image_html() : string
- Cleanup image HTML.
- get_block_wrapper() : string
- Based on MJML <mj-image> but because MJML doesn't support captions, our solution is a bit different
- get_caption_styles() : string
- This method configure the font size of the caption because it's set to 0 for the parent element to avoid unexpected white spaces We try to use font-size passed down from the parent element $parsedBlock['email_attrs']['font-size'], but if it's not set, we use the default font-size from the email theme.
- parse_block_content() : array{imageUrl: string, image: string, caption: string, class: string}|null
- Parse block content to get image URL, image HTML and caption HTML.
- remove_style_attribute_from_element() : string
- Remove style attribute from the element.
Methods
render()
Render the block.
public
render(string $block_content, array<string|int, mixed> $parsed_block, Settings_Controller $settings_controller) : string
Parameters
- $block_content : string
-
The block content.
- $parsed_block : array<string|int, mixed>
-
The parsed block.
- $settings_controller : Settings_Controller
-
The settings controller.
Return values
string —add_spacer()
Add a spacer around the block.
protected
add_spacer(string $content, array<string|int, mixed> $email_attrs) : string
Parameters
- $content : string
-
The block content.
- $email_attrs : array<string|int, mixed>
-
The email attributes.
Return values
string —compile_css()
Compile objects containing CSS properties to a string.
protected
compile_css(array<string|int, mixed> ...$styles) : string
Parameters
- $styles : array<string|int, mixed>
-
Style arrays to compile.
Return values
string —get_styles_from_block()
Wrapper for wp_style_engine_get_styles which ensures all values are returned.
protected
get_styles_from_block(array<string|int, mixed> $block_styles[, bool $skip_convert_vars = false ]) : array<string|int, mixed>
Parameters
- $block_styles : array<string|int, mixed>
-
Array of block styles.
- $skip_convert_vars : bool = false
-
If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format.
Return values
array<string|int, mixed> —render_content()
Renders the block content.
protected
render_content(string $block_content, array<string|int, mixed> $parsed_block, Settings_Controller $settings_controller) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $settings_controller : Settings_Controller
-
Settings controller.
Return values
string —add_image_size_when_missing()
When the width is not set, it's important to get it for the image to be displayed correctly
private
add_image_size_when_missing(array<string|int, mixed> $parsed_block, string $image_url, Settings_Controller $settings_controller) : array<string|int, mixed>
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $image_url : string
-
Image URL.
- $settings_controller : Settings_Controller
-
Settings controller.
Return values
array<string|int, mixed> —add_style_to_element()
Add style to the element.
private
add_style_to_element(string $block_content, array{tag_name: string, class_name?: string} $tag, string $style) : string
Parameters
- $block_content : string
-
Block content.
- $tag : array{tag_name: string, class_name?: string}
-
Tag to add style to.
- $style : string
-
Style to add.
Return values
string —addImageDimensions()
Settings width and height attributes for images is important for MS Outlook.
private
addImageDimensions(string $block_content, array<string|int, mixed> $parsed_block, Settings_Controller $settings_controller) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $settings_controller : Settings_Controller
-
Settings controller.
Return values
string —apply_image_border_style()
Apply border style to the image.
private
apply_image_border_style(string $block_content, array<string|int, mixed> $parsed_block, string $class_name) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $class_name : string
-
Class name.
Return values
string —apply_rounded_style()
Apply rounded style to the image.
private
apply_rounded_style(string $block_content, array<string|int, mixed> $parsed_block) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
Return values
string —cleanup_image_html()
Cleanup image HTML.
private
cleanup_image_html(string $content_html) : string
Parameters
- $content_html : string
-
Content HTML.
Return values
string —get_block_wrapper()
Based on MJML <mj-image> but because MJML doesn't support captions, our solution is a bit different
private
get_block_wrapper(array<string|int, mixed> $parsed_block, Settings_Controller $settings_controller, string|null $caption) : string
Parameters
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $settings_controller : Settings_Controller
-
Settings controller.
- $caption : string|null
-
Caption.
Return values
string —get_caption_styles()
This method configure the font size of the caption because it's set to 0 for the parent element to avoid unexpected white spaces We try to use font-size passed down from the parent element $parsedBlock['email_attrs']['font-size'], but if it's not set, we use the default font-size from the email theme.
private
get_caption_styles(Settings_Controller $settings_controller, array<string|int, mixed> $parsed_block) : string
Parameters
- $settings_controller : Settings_Controller
-
Settings controller.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
Return values
string —parse_block_content()
Parse block content to get image URL, image HTML and caption HTML.
private
parse_block_content(string $block_content) : array{imageUrl: string, image: string, caption: string, class: string}|null
Parameters
- $block_content : string
-
Block content.
Return values
array{imageUrl: string, image: string, caption: string, class: string}|null —remove_style_attribute_from_element()
Remove style attribute from the element.
private
remove_style_attribute_from_element(string $block_content, array{tag_name: string, class_name?: string} $tag, string $style_name) : string
Parameters
- $block_content : string
-
Block content.
- $tag : array{tag_name: string, class_name?: string}
-
Tag to remove style from.
- $style_name : string
-
Name of the style to remove.