function theme_money_formatter_generic in Money field 6
Display a CCK Money field (formatted).
1 string reference to 'theme_money_formatter_generic'
- money_theme in ./
money.module - Implementation of hook_theme().
File
- ./
money.module, line 413 - This module defines the Money CCK field.
Code
function theme_money_formatter_generic($element) {
$amount = isset($element['#item']['amount']) ? $element['#item']['amount'] : NULL;
if (!is_numeric($amount)) {
return '';
}
$field = content_fields($element['#field_name'], $element['#type_name']);
$currency = $element['#item']['currency'];
// The number of decimals depends on the formatter being used and
// the field options.
if ($element['#formatter'] == 'nozeros') {
// For this formatter we display only relevant zeros.
$decimals = -1;
}
else {
// See if the precision should be taken from the field itself or from the currency data.
if (isset($field['widget']['decimals_display_mode']) && $field['widget']['decimals_display_mode'] == 'currency') {
$currencies = currency_api_get_currencies();
if (isset($currencies[$currency]['decimals'])) {
$decimals = $currencies[$currency]['decimals'];
}
}
}
// When no decimals have been set, use the number from the field settings.
if (!isset($decimals)) {
$decimals = isset($field['decimals']) ? (int) $field['decimals'] : 0;
}
// Format the amount.
$formatted_number = format_number($amount, $decimals);
// Format the whole field based on widget display options.
return theme('money_field', $formatted_number, $currency, $field['widget']['currency_display_mode']);
}