You are here

function list_field_formatter_view in Drupal 7

Implements hook_field_formatter_view().

File

modules/field/modules/list/list.module, line 460
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();
  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;
  }
  return $element;
}