Allow Styling of currency values generated by format() method of CurrencyFormat Helper

by T. Chance Vecchitto ยท 2 years ago

Would be nice to be able to pass an additional option parameter to the format() method of CurrencyFormat class. This additional parameter would have the helper wrap NEGATIVE values with a element that can then be styled in a view to show in color, wrapped in parenthesis, etc.

Currently, Blesta wraps the value as follows:

// Wrap the currency code in a span tag
if ($html_wrap_code) {
$value .= ' ' . $currency . '';
}

if ($options['html_code']) {
$value = '' . $value . '';
}

I propose an added test for negative value and where the option is set. This would be inserted just above the return $value line:

// value is negative and options['html_wrap_negative'] is true?
if( strpos($value, '-') !== false && $options['html_wrap_negative'] ) {
$value = '' . $value . '';
}

This four-line addition to the format() method allows us to show negative currency values like traditional systems do. By using an added option and a span element with the CSS class name allows others to either take advantage or not.

Comments (0)

No comments yet. Be the first to share your thoughts!

2

2 voters

Status Under Review