You are here

function bigint_field_formatter_view in Big Integer 7

Implements hook_field_formatter_view().

File

./bigint.module, line 222
Defines numeric field types.

Code

function bigint_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  switch ($display['type']) {
    case 'number_bigint':
      foreach ($items as $delta => $item) {
        $output = bigint_number_format($item['value'], $settings['thousand_separator']);
        if ($settings['prefix_suffix']) {
          $prefixes = isset($instance['settings']['prefix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['prefix'])) : array(
            '',
          );
          $suffixes = isset($instance['settings']['suffix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['suffix'])) : array(
            '',
          );
          $prefix = count($prefixes) > 1 ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : $prefixes[0];
          $suffix = count($suffixes) > 1 ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : $suffixes[0];
          $output = $prefix . $output . $suffix;
        }
        $element[$delta] = array(
          '#markup' => $output,
        );
      }
      break;
    case 'number_unformatted':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => $item['value'],
        );
      }
      break;
  }
  return $element;
}