Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_border_radius_class_and_style()public staticWC 1.0

Get class and style for border-radius from attributes.

Method of the class: StyleAttributesUtils{}

No Hooks.

Return

Array.

Usage

$result = StyleAttributesUtils::get_border_radius_class_and_style( $attributes );
$attributes(array) (required)
Block attributes.

StyleAttributesUtils::get_border_radius_class_and_style() code WC 9.4.2

public static function get_border_radius_class_and_style( $attributes ) {
	$custom_border_radius = $attributes['style']['border']['radius'] ?? '';

	if ( '' === $custom_border_radius ) {
		return self::EMPTY_STYLE;
	}

	$style = '';

	if ( is_string( $custom_border_radius ) ) {
		// Linked sides.
		$style = 'border-radius:' . $custom_border_radius . ';';
	} else {
		// Unlinked sides.
		$border_radius = array();

		$border_radius['border-top-left-radius']     = $custom_border_radius['topLeft'] ?? '';
		$border_radius['border-top-right-radius']    = $custom_border_radius['topRight'] ?? '';
		$border_radius['border-bottom-right-radius'] = $custom_border_radius['bottomRight'] ?? '';
		$border_radius['border-bottom-left-radius']  = $custom_border_radius['bottomLeft'] ?? '';

		foreach ( $border_radius as $border_radius_side => $border_radius_value ) {
			if ( '' !== $border_radius_value ) {
				$style .= $border_radius_side . ':' . $border_radius_value . ';';
			}
		}
	}

	return array(
		'class' => null,
		'style' => $style,
	);
}