You are here

function mvf_property_info_alter in Measured Value Field 7

Property info alter callback for MVF field structure.

We will examine what MVF it is, what units are available for that MVF and for each of those units will generate additional property of converted value.

1 string reference to 'mvf_property_info_alter'
mvf_property_info_callback in ./mvf.module
Callback to alter the property info of mvf field.

File

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

Code

function mvf_property_info_alter(EntityMetadataWrapper $wrapper, array $propertyInfo) {
  $mvf_info = $wrapper
    ->info();
  $mvf_field = field_info_field($mvf_info['name']);
  $measure = mvf_measure_extract($mvf_field);
  foreach (units_unit_by_measure_load_multiple($measure) as $unit) {
    $key = 'converted_' . entity_id($unit
      ->entityType(), $unit);
    $propertyInfo['properties'][$key] = $propertyInfo['properties']['value'];
    unset($propertyInfo['properties'][$key]['schema field']);
    unset($propertyInfo['properties'][$key]['setter callback']);
    $propertyInfo['properties'][$key]['getter callback'] = 'mvf_entity_property_converted_get';
    $propertyInfo['properties'][$key]['computed'] = TRUE;
    $propertyInfo['properties'][$key]['label'] = t('Value in @label', array(
      '@label' => entity_label($unit
        ->entityType(), $unit),
    ));
    $ids = entity_extract_ids($unit
      ->entityType(), $unit);

    // We store in the property info the conversion target unit, so the getter
    // callback can easily access it.
    $propertyInfo['properties'][$key]['mvf target unit'] = $ids[0];
  }
  return $propertyInfo;
}