Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_margin_class_and_style()public staticWC 1.0

Get class and style for margin from attributes.

Method of the class: StyleAttributesUtils{}

No Hooks.

Return

Array.

Usage

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

StyleAttributesUtils::get_margin_class_and_style() code WC 9.4.2

public static function get_margin_class_and_style( $attributes ) {
	$margin = $attributes['style']['spacing']['margin'] ?? null;

	if ( ! $margin ) {
		return self::EMPTY_STYLE;
	}

	$spacing_values_css = '';

	foreach ( $margin as $margin_side => $margin_value ) {
		$spacing_values_css .= 'margin-' . $margin_side . ':' . self::get_spacing_value( $margin_value ) . ';';
	}

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