You are here

function theme_number_formatter_generic in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 modules/number/number.module \theme_number_formatter_generic()
  2. 6.2 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 266
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];
    }
  }
  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 = explode('|', $field['prefix']);
  $suffixes = explode('|', $field['suffix']);
  $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;
}