You are here

function text_field_formatter in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6 examples/simple_field.php \text_field_formatter()
  2. 6 examples/example_field.php \text_field_formatter()

Implementation of hook_field_formatter().

The $node argument is necessary so that filter access can be checked on node preview.

File

./text.module, line 219
Defines simple text field types.

Code

function text_field_formatter($field, $item, $formatter, $node) {
  if (!isset($item['value'])) {
    return '';
  }
  if ($allowed_values = text_allowed_values($field)) {
    return $allowed_values[$item['value']];
  }
  switch ($formatter) {
    case 'plain':
      $text = strip_tags($item['value']);
      break;
    case 'trimmed':
      $text = node_teaser($item['value'], $field['text_processing'] ? $item['format'] : NULL);
      break;
    case 'default':
      $text = $item['value'];
  }
  if ($field['text_processing']) {
    return check_markup($text, $item['format'], is_null($node) || isset($node->in_preview));
  }
  else {
    return check_plain($text);
  }
}