You are here

function theme_number_formatter_generic in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 modules/number/number.module \theme_number_formatter_generic()
  2. 6 modules/number/number.module \theme_number_formatter_generic()

Proxy theme function for number field formatters.

1 string reference to 'theme_number_formatter_generic'
number_theme in modules/number/number.module
Implementation of hook_theme().

File

modules/number/number.module, line 292
Defines numeric field types.

Code

function theme_number_formatter_generic($element) {
  $field = content_fields($element['#field_name'], $element['#type_name']);
  $value = $element['#item']['value'];
  if ($allowed_values = content_allowed_values($field)) {
    if (isset($allowed_values[$value]) && $allowed_values[$value] != $value) {
      return $allowed_values[$value];
    }
  }
  if (empty($value) && $value !== '0') {
    return '';
  }
  switch ($element['#formatter']) {
    case 'us_0':
      $output = number_format($value, 0, '.', ',');
      break;
    case 'us_1':
      $output = number_format($value, 1, '.', ',');
      break;
    case 'us_2':
      $output = number_format($value, 2, '.', ',');
      break;
    case 'be_0':
      $output = number_format($value, 0, ',', '.');
      break;
    case 'be_1':
      $output = number_format($value, 1, ',', '.');
      break;
    case 'be_2':
      $output = number_format($value, 2, ',', '.');
      break;
    case 'fr_0':
      $output = number_format($value, 0, ', ', ' ');
      break;
    case 'fr_1':
      $output = number_format($value, 1, ', ', ' ');
      break;
    case 'fr_2':
      $output = number_format($value, 2, ', ', ' ');
      break;
    default:
      $output = $value;
      break;
  }
  $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(
    '',
  );
  $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array(
    '',
  );
  $prefix = count($prefixes) > 1 ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0];
  $suffix = count($suffixes) > 1 ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0];
  return $prefix . $output . $suffix;
}