function theme_mvf_formatter_generic in Measured Value Field 6
Display a MVF field (formatted).
1 string reference to 'theme_mvf_formatter_generic'
- mvf_theme in ./
mvf.module - Implementation of hook_theme().
File
- ./
mvf.module, line 692 - Measured Value Field module.
Code
function theme_mvf_formatter_generic($element) {
$value = isset($element['#item']['value']) ? $element['#item']['value'] : NULL;
$value2 = isset($element['#item']['value2']) ? $element['#item']['value2'] : NULL;
if (!is_numeric($value)) {
return '';
}
$field = content_fields($element['#field_name'], $element['#type_name']);
$unit = $element['#item']['unit'];
// 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 unit data.
if (isset($field['widget']['decimals_display_mode']) && $field['widget']['decimals_display_mode'] == 'unit') {
$units = units_get_units();
if (isset($units[$unit]['decimals'])) {
$decimals = $units[$unit]['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 values.
// Empty "To" value is stored as equal to the "From" value.
// We display field as single value if both values are equal.
$formatted_number = format_number($value, $decimals);
if ($value2 != '' && $value2 != $value) {
$formatted_number2 = format_number($value2, $decimals);
$display_mode = $field['widget']['unit_display_mode_range'];
}
else {
$formatted_number2 = '';
$display_mode = $field['widget']['unit_display_mode_single'];
}
// Format the whole field based on widget display options.
return theme('mvf_field', $formatted_number, $formatted_number2, $unit, $display_mode);
}