function field_hidden_field_formatter_view in Field Hidden 7
Defines the display of a field's value; formats field value for display in a piece of content.
Implements hook_field_formatter_view().
Parameters
string $entity_type:
string $entity:
array $field:
array $instance:
string $langcode:
array $items:
array $display:
Return value
array
File
- ./
field_hidden.module, line 750 - Drupal Field Hidden module
Code
function field_hidden_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$element = array();
switch ($display['type']) {
case 'field_hidden_integer':
foreach ($items as $delta => $item) {
$output = number_format($item['value'], 0, '', $settings['thousand_separator']);
if ($settings['prefix_suffix']) {
$prefixes = isset($instance['settings']['prefix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['prefix'])) : array(
'',
);
$suffixes = isset($instance['settings']['suffix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['suffix'])) : array(
'',
);
$prefix = count($prefixes) > 1 ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : $prefixes[0];
$suffix = count($suffixes) > 1 ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : $suffixes[0];
$output = $prefix . $output . $suffix;
}
$element[$delta] = array(
'#markup' => $output,
);
}
break;
case 'field_hidden_decimal':
foreach ($items as $delta => $item) {
$output = number_format($item['value'], $settings['scale'], $settings['decimal_separator'], $settings['thousand_separator']);
if ($settings['prefix_suffix']) {
$prefixes = isset($instance['settings']['prefix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['prefix'])) : array(
'',
);
$suffixes = isset($instance['settings']['suffix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['suffix'])) : array(
'',
);
$prefix = count($prefixes) > 1 ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : $prefixes[0];
$suffix = count($suffixes) > 1 ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : $suffixes[0];
$output = $prefix . $output . $suffix;
}
$element[$delta] = array(
'#markup' => $output,
);
}
break;
case 'field_hidden_numeric_unformatted':
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#markup' => $item['value'],
);
}
break;
case 'field_hidden_text_plain':
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#markup' => strip_tags($item['value']),
);
}
break;
default:
// field_hidden_text_plain_escaped
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#markup' => htmlspecialchars(strip_tags($item['value']), ENT_QUOTES, 'UTF-8'),
);
}
}
return $element;
}