1 text.module | text_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) |
Implements hook_field_formatter_view().
File
- core/
modules/ field/ modules/ text/ text.module, line 320 - 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) {
if (empty($item['value'])) {
continue;
}
$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']) && empty($item['value'])) {
continue;
}
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;
}