You are here

function units_field_field_settings_form in Units of Measurement 7.2

Implements hook_field_settings_form().

File

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

Code

function units_field_field_settings_form($field, $instance, $has_data) {
  $form = array();
  switch ($field['type']) {
    case 'units_value':
      $form['dimension'] = array(
        '#tree' => TRUE,
      );
      $form['dimension']['type'] = array(
        '#type' => 'radios',
        '#title' => t('Format to specify dimension of this field'),
        '#options' => array(
          'measure' => t('By selecting a measure'),
          'mathematical_expression' => t('By entering mathematical expression'),
        ),
        '#default_value' => $field['settings']['dimension']['type'],
        '#disabled' => $has_data,
      );
      $mathematical_expression = units_mathematical_expression_create_from_postfix($field['settings']['dimension']['mathematical_expression']);
      $form['dimension']['mathematical_expression'] = array(
        '#type' => 'units_mathematical_expression',
        '#title' => t('Mathematical expression'),
        '#description' => t('Specify here mathematical expression that defines dimension of this field.'),
        '#default_value' => $mathematical_expression,
        '#value_format' => 'postfix',
        '#states' => array(
          'visible' => array(
            ':radio[name$="[dimension][type]"]' => array(
              'value' => 'mathematical_expression',
            ),
          ),
        ),
        '#disabled' => $has_data,
      );
      $options = array();
      foreach (units_measure_load_multiple() as $measure) {
        $options[$measure
          ->identifier()] = entity_label($measure
          ->entityType(), $measure);
      }
      $form['dimension']['measure'] = array(
        '#type' => 'radios',
        '#title' => t('Select underlying measure for this field'),
        '#options' => $options,
        '#default_value' => isset($field['settings']['dimension']['measure']) ? $field['settings']['dimension']['measure'] : NULL,
        '#disabled' => $has_data,
        '#states' => array(
          'visible' => array(
            ':radio[name$="[dimension][type]"]' => array(
              'value' => 'measure',
            ),
          ),
        ),
      );
      break;
  }
  return $form;
}