1 field_test.field.inc field_test_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)

Implements hook_field_formatter_view().

File

core/modules/field/tests/field_test/field_test.field.inc, line 373
Defines a field type and its formatters and widgets.

Code

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

  switch ($display['type']) {
    case 'field_test_default':
      foreach ($items as $delta => $item) {
        $element[$delta] = array('#markup' => $settings['test_formatter_setting'] . '|' . $item['value']);
      }
      break;

    case 'field_test_with_prepare_view':
      foreach ($items as $delta => $item) {
        $element[$delta] = array('#markup' => $settings['test_formatter_setting_additional'] . '|' . $item['value'] . '|' . $item['additional_formatter_value']);
      }
      break;

    case 'field_test_multiple':
      if (!empty($items)) {
        $array = array();
        foreach ($items as $delta => $item) {
          $array[] = $delta . ':' . $item['value'];
        }
        $element[0] = array('#markup' => $settings['test_formatter_setting_multiple'] . '|' . implode('|', $array));
      }
      break;
  }

  return $element;
}