Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_background_color_class_and_style()public staticWC 1.0

Get class and style for background-color from attributes.

Метод класса: StyleAttributesUtils{}

Хуков нет.

Возвращает

Массив.

Использование

$result = StyleAttributesUtils::get_background_color_class_and_style( $attributes );
$attributes(массив) (обязательный)
Block attributes.

Код StyleAttributesUtils::get_background_color_class_and_style() WC 8.7.0

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,
	);
}