function money_field_formatter in Money field 5
Implementation of hook_field_formatter().
File
- ./
money.module, line 226 - This module defines the "money" CCK field. It uses the Currency API, which is included in the Currency module, to get a list of valid currencies.
Code
function money_field_formatter($field, $item, $formatter, $node) {
if (empty($item['amount'])) {
return '';
}
else {
$decimal_separator = _money_get_decimal_separator($field['decimal_separator']);
$digit_group_separator = _money_get_digit_group_separator($field['digit_group_separator']);
$displayed_decimals = _money_get_displayed_decimals($field['displayed_decimals']);
$formatted_amount = check_plain(number_format($item['amount'] / 100, $displayed_decimals, $decimal_separator, $digit_group_separator));
$currencies = currency_api_get_list();
$symbols = currency_api_get_symbols();
switch ($formatter) {
case 'code_after_amount':
return $formatted_amount . ' ' . $item['currency'];
case 'code_before_amount':
return $item['currency'] . ' ' . $formatted_amount;
case 'full_after_amount':
return $formatted_amount . ' ' . $currencies[$item['currency']];
case 'full_before_amount':
return $currencies[$item['currency']] . ' ' . $formatted_amount;
case 'symbol_after_amount':
return $formatted_amount . ' ' . $symbols[$item['currency']];
case 'symbol_before_amount':
return $symbols[$item['currency']] . ' ' . $formatted_amount;
}
}
}