You are here

function uc_store_address_fields_form in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_store/uc_store.module \uc_store_address_fields_form()
  2. 6.2 uc_store/uc_store.module \uc_store_address_fields_form()

Form to configure address fields.

See also

uc_store_address_fields_form_submit()

theme_uc_store_address_fields_form()

1 string reference to 'uc_store_address_fields_form'
uc_store_menu in uc_store/uc_store.module
Implements hook_menu().

File

uc_store/uc_store.admin.inc, line 124
Store administration menu items.

Code

function uc_store_address_fields_form($form, &$form_state) {
  $form['uc_address_fields']['#tree'] = TRUE;
  $form['uc_address_fields_required']['#tree'] = TRUE;
  $form['uc_address_fields_weight']['#tree'] = TRUE;
  $fields = array(
    'first_name' => t('First name'),
    'last_name' => t('Last name'),
    'company' => t('Company'),
    'street1' => t('Street address 1'),
    'street2' => t('Street address 2'),
    'city' => t('City'),
    'zone' => t('State/Province'),
    'country' => t('Country'),
    'postal_code' => t('Postal code'),
    'phone' => t('Phone number'),
  );
  $current = variable_get('uc_address_fields', drupal_map_assoc(array(
    'first_name',
    'last_name',
    'phone',
    'company',
    'street1',
    'street2',
    'city',
    'zone',
    'postal_code',
    'country',
  )));
  $required = variable_get('uc_address_fields_required', drupal_map_assoc(array(
    'first_name',
    'last_name',
    'street1',
    'city',
    'zone',
    'postal_code',
    'country',
  )));
  $weight = uc_store_address_field_weights();
  foreach ($fields as $field => $label) {
    $form['uc_address_fields'][$field] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($current[$field]) ? TRUE : FALSE,
    );
    $form['uc_address_fields_required'][$field] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($required[$field]) ? TRUE : FALSE,
    );
    $form['uc_address_fields_weight'][$field] = array(
      '#type' => 'weight',
      '#default_value' => isset($weight[$field]) ? $weight[$field] : 0,
      '#attributes' => array(
        'class' => array(
          'uc-store-address-fields-weight',
        ),
      ),
    );
    $form['fields'][$field]['default'] = array(
      '#markup' => $label,
    );
    $form['fields'][$field]['uc_field_' . $field] = array(
      '#type' => 'textfield',
      '#default_value' => uc_get_field_name($field),
      '#size' => 32,
    );
    $form['fields'][$field]['#weight'] = isset($weight[$field]) ? $weight[$field] : 99;
  }
  $form['#submit'][] = 'uc_store_address_fields_form_submit';
  if (function_exists('i18n_variable_form_alter_settings')) {
    if ($i18n_variables = i18n_variable_form_alter_settings($form, i18n_variable_list())) {
      $form['#submit'][] = 'i18n_variable_form_submit';
      $form['#i18n_variables'] = $i18n_variables;
      $form += i18n_variable_form_selector();
    }
  }
  $form = system_settings_form($form);
  unset($form['#theme']);
  return $form;
}