Automattic\WooCommerce\EmailEditor\Integrations\Utils
Styles_Helper::get_normalized_block_styles
Get normalized block styles by translating color slugs to actual color values.
This method handles the normalization of color-related attributes like backgroundColor, textColor, borderColor, and linkColor by translating them from slugs to actual color values using the rendering context.
Method of the class: Styles_Helper{}
No Hooks.
Returns
Array. Normalized block styles with translated color values.
Usage
$result = Styles_Helper::get_normalized_block_styles( $block_attributes, $rendering_context ): array;
- $block_attributes(array) (required)
- Block attributes containing color slugs.
- $rendering_context(Rendering_Context) (required)
- Rendering context for color translation.
Styles_Helper::get_normalized_block_styles() Styles Helper::get normalized block styles code WC 10.4.3
public static function get_normalized_block_styles( array $block_attributes, Rendering_Context $rendering_context ): array {
$normalized_colors = array_filter(
array(
'color' => array_filter(
array(
'background' => isset( $block_attributes['backgroundColor'] ) && $block_attributes['backgroundColor']
? $rendering_context->translate_slug_to_color( $block_attributes['backgroundColor'] )
: null,
'text' => isset( $block_attributes['textColor'] ) && $block_attributes['textColor']
? $rendering_context->translate_slug_to_color( $block_attributes['textColor'] )
: null,
)
),
'border' => array_filter(
array(
'color' => isset( $block_attributes['borderColor'] ) && $block_attributes['borderColor']
? $rendering_context->translate_slug_to_color( $block_attributes['borderColor'] )
: null,
)
),
)
);
return array_replace_recursive(
$normalized_colors,
$block_attributes['style'] ?? array()
);
}