Automattic\WooCommerce\Blocks\Utils
StyleAttributesUtils::get_background_color_class_and_style
Get class and style for background-color from attributes.
Method of the class: StyleAttributesUtils{}
No Hooks.
Returns
Array.
Usage
$result = StyleAttributesUtils::get_background_color_class_and_style( $attributes );
- $attributes(array) (required)
- Block attributes.
StyleAttributesUtils::get_background_color_class_and_style() StyleAttributesUtils::get background color class and style code WC 10.3.6
public static function get_background_color_class_and_style( $attributes ) {
$gradient = $attributes['gradient'] ?? null;
$background_color = $attributes['backgroundColor'] ?? '';
$custom_background_color = $attributes['style']['color']['background'] ?? '';
$classes = [ $gradient ];
$styles = [];
$value = null;
if ( $background_color || $custom_background_color || $gradient ) {
$classes[] = 'has-background';
}
if ( $background_color ) {
$classes[] = sprintf( 'has-%s-background-color', $background_color );
$value = self::get_preset_value( $background_color );
}
if ( $custom_background_color ) {
$styles[] = sprintf( 'background-color: %s;', $custom_background_color );
$value = $custom_background_color;
}
if ( $gradient ) {
$classes[] = sprintf( 'has-%s-gradient-background', $gradient );
}
return array(
'class' => self::join_styles( $classes ),
'style' => self::join_styles( $styles ),
'value' => $value,
);
}