You are here

function field_test_field_formatter_view in Drupal 7

Implements hook_field_formatter_view().

File

modules/field/tests/field_test.field.inc, line 367
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;
}