1 list.module list_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)

Implements hook_field_formatter_view().

File

core/modules/field/modules/list/list.module, line 509
Defines list field types that can be used with the Options module.

Code

function list_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];

  switch ($display['type']) {
    case 'list_default':
      $allowed_values = list_allowed_values($field, $instance, $entity_type, $entity);
      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;

    case 'list_key':
      foreach ($items as $delta => $item) {
        $element[$delta] = array('#markup' => field_filter_xss($item['value']));
      }
      break;
    case 'boolean_yes_no':
      foreach ($items as $delta => $item) {
        $output = list_boolean_display_value_with_format($item['value'], $settings['format'], $settings);
        $element[$delta] = array('#markup' => field_filter_xss($output));
      }
      break;
  }

  return $element;
}