You are here

function units_field_dimension in Units of Measurement 7.2

Retrieve allowed dimension for a provided field.

Parameters

array $field: Field definition array for which to determine allowed dimension

Return value

array Dimension array that is allowed in the provided field

2 calls to units_field_dimension()
units_field_field_formatter_settings_form in units_field/units_field.module
Implements hook_field_formatter_settings_form().
units_field_field_widget_form in units_field/units_field.module
Implements hook_field_widget_form().

File

units_field/units_field.module, line 308
Provide field type for storing measured values.

Code

function units_field_dimension($field) {
  $mathematical_expression = NULL;
  switch ($field['settings']['dimension']['type']) {
    case 'mathematical_expression':
      $mathematical_expression = units_mathematical_expression_create_from_postfix($field['settings']['dimension']['mathematical_expression'])
        ->getExpression();
      break;
    case 'measure':
      $efq = new EntityFieldQuery();
      $efq
        ->entityCondition('entity_type', 'units_unit');
      $efq
        ->entityCondition('bundle', $field['settings']['dimension']['measure']);
      $efq
        ->range(0, 1);
      $result = $efq
        ->execute();
      $result = array_keys($result['units_unit']);
      $mathematical_expression = units_unit_load(reset($result));
      break;
  }
  return $mathematical_expression
    ->dimension();
}