You are here

function mvf_entity_property_converted_get in Measured Value Field 7

Property getter callback for MVF converted values.

Return MVF value converted into requested unit.

1 string reference to 'mvf_entity_property_converted_get'
mvf_property_info_alter in ./mvf.module
Property info alter callback for MVF field structure.

File

./mvf.module, line 2000
Define a field type of measured value.

Code

function mvf_entity_property_converted_get($data, array $options, $name, $type, $info) {
  $units = array(
    $data[mvf_subfield_to_column('unit')],
    $info['mvf target unit'],
  );
  $units = units_unit_load_multiple($units);
  $from = $units[$data[mvf_subfield_to_column('unit')]];
  $from = entity_id($from
    ->entityType(), $from);
  $to = $units[$info['mvf target unit']];
  $to = entity_id($to
    ->entityType(), $to);
  return units_convert($data[mvf_subfield_to_column('value')], $from, $to);
}