You are here

function range_field_formatter_view in Range 7

Implements hook_field_formatter_view().

File

./range.module, line 455
Defines range field types.

Code

function range_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  $instance = range_translate_field_instance($instance);
  foreach ($items as $delta => $item) {
    $from_value = _range_number_format($item['from'], $display['type'], $settings);
    $to_value = _range_number_format($item['to'], $display['type'], $settings);

    // Combine values if they are equal.
    if (!empty($settings['range_combine']) && $from_value === $to_value) {
      $output = _range_field_formatter_view_combined_value($from_value, $settings, $instance['settings']);
    }
    else {
      $output = _range_field_formatter_view_separate_values($from_value, $to_value, $settings, $instance['settings']);
    }

    // Add field prefix/suffix.
    $output = _range_field_formatter_view_prefix_suffix($output, $settings['field_prefix_suffix'], $instance['settings']['field']);
    $element[$delta] = array(
      '#markup' => $output,
    );
  }
  return $element;
}