You are here

function money_field_settings in Money field 6

Same name and namespace in other branches
  1. 5 money.module \money_field_settings()

Implementation of hook_field_settings().

File

./money.module, line 40
This module defines the Money CCK field.

Code

function money_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['precision'] = array(
        '#type' => 'select',
        '#title' => t('Precision'),
        '#options' => drupal_map_assoc(range(1, 20)),
        '#default_value' => is_numeric($field['precision']) && (int) $field['precision'] > 0 ? $field['precision'] : 10,
        '#description' => t('The total number of digits to store in the database, including digits to the right of the decimal point.'),
      );
      $form['decimals'] = array(
        '#type' => 'select',
        '#title' => t('Decimals'),
        '#options' => drupal_map_assoc(range(0, FORMAT_NUMBER_MAX_PRECISION)),
        '#default_value' => is_numeric($field['decimals']) && (int) $field['decimals'] >= 0 ? $field['decimals'] : 2,
        '#description' => t('The number of digits to the right of the decimal point.'),
      );
      formatted_number_add_js();
      return $form;
    case 'save':
      return array(
        'precision',
        'decimals',
      );
    case 'database columns':
      $precision = isset($field['precision']) ? $field['precision'] : 10;
      $decimals = isset($field['decimals']) ? $field['decimals'] : 2;
      return array(
        'amount' => array(
          'type' => 'numeric',
          'precision' => $precision,
          'scale' => $decimals,
          'not null' => FALSE,
          'sortable' => TRUE,
          'views' => TRUE,
        ),
        'currency' => array(
          'type' => 'varchar',
          'length' => 3,
          'not null' => FALSE,
          'sortable' => TRUE,
          'views' => TRUE,
        ),
      );
  }
}