function list_field_formatter_view

Implements hook_field_formatter_view().

File

modules/field/modules/list/list.module, line 461

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.