You are here

function i18n_field_field_formatter_view in Internationalization 7

Implements hook_field_formatter_view().

File

i18n_field/i18n_field.module, line 138
Internationalization (i18n) module - Field handling

Code

function i18n_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'i18n_list_default':
      if ($translate = i18n_field_type_info($field['type'], 'translate_options')) {
        $allowed_values = $translate($field);
      }
      else {

        // Defaults to list_default behavior
        $allowed_values = list_allowed_values($field);
      }
      foreach ($items as $delta => $item) {
        if (isset($allowed_values[$item['value']])) {
          $output = field_filter_xss($allowed_values[$item['value']]);
        }
        else {

          // If no match was found in allowed values, fall back to the key.
          $output = field_filter_xss($item['value']);
        }
        $element[$delta] = array(
          '#markup' => $output,
        );
      }
      break;
  }
  return $element;
}