function units_field_field_formatter_view in Units of Measurement 7.2
Implements hook_field_formatter_view().
File
- units_field/
units_field.module, line 274 - Provide field type for storing measured values.
Code
function units_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'units_value_expression':
foreach ($items as $delta => $item) {
$output_mathematical_expression = units_field_display_mathematical_expression($display);
if (is_object($output_mathematical_expression)) {
$output_mathematical_expression = $output_mathematical_expression
->getExpression();
units_mathematical_expression_format_as($item['expression']
->getExpression(), $output_mathematical_expression);
}
else {
// Since no output format was given, we output it in original
// mathematical expression.
$output_mathematical_expression = $item['expression']
->getExpression();
}
$element[$delta] = array(
'#markup' => check_plain($output_mathematical_expression
->toInfix()),
);
}
break;
}
return $element;
}