You are here

function text_field_formatter_view in Drupal 7

Implements hook_field_formatter_view().

File

modules/field/modules/text/text.module, line 259
Defines simple text field types.

Code

function text_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'text_default':
    case 'text_trimmed':
      foreach ($items as $delta => $item) {
        $output = _text_sanitize($instance, $langcode, $item, 'value');
        if ($display['type'] == 'text_trimmed') {
          $output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $display['settings']['trim_length']);
        }
        $element[$delta] = array(
          '#markup' => $output,
        );
      }
      break;
    case 'text_summary_or_trimmed':
      foreach ($items as $delta => $item) {
        if (!empty($item['summary'])) {
          $output = _text_sanitize($instance, $langcode, $item, 'summary');
        }
        else {
          $output = _text_sanitize($instance, $langcode, $item, 'value');
          $output = text_summary($output, $instance['settings']['text_processing'] ? $item['format'] : NULL, $display['settings']['trim_length']);
        }
        $element[$delta] = array(
          '#markup' => $output,
        );
      }
      break;
    case 'text_plain':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => strip_tags($item['value']),
        );
      }
      break;
  }
  return $element;
}