You are here

function _uc_extra_fields_pane_applyWeights in Extra Fields Checkout Pane 6.2

_applyWeights() Applies ordering to address fields following the 'uc_address_fields_weight'-settings. This function is used by some form-alter functions of this module that alters address forms.

@access private

Parameters

array $form_part:

string $prefix: On the checkout-form the address fields got prefixes: 'delivery_' & 'billing_'.

Return value

void

4 calls to _uc_extra_fields_pane_applyWeights()
uc_extra_fields_pane_form_alter in ./uc_extra_fields_pane.module
Implementation of hook_form_alter().
uc_extra_fields_pane_form_uc_order_edit_form_alter in ./uc_extra_fields_pane.module
Implementation of hook_form_FORM_ID_alter(). Applies ordering to address fields following the 'uc_address_fields_weight'-settings.
uc_extra_fields_pane_uc_addresses_address_field_alter in ./uc_extra_fields_pane.module
Implementation of hook_uc_addresses_address_field_alter().
uc_extra_fields_pane_weight_uc_cart_checkout_form_alter in includes/weights.inc
uc_extra_fields_pane_weight_uc_cart_checkout_form_alter(). Applies ordering to address fields following the 'uc_address_fields_weight'-settings.

File

includes/weights.inc, line 172
These functions adds weight to the address fields, so it becomes possible to change the order of the address fields.

Code

function _uc_extra_fields_pane_applyWeights(&$form_part, $prefix = '') {

  // Get weight settings
  $weights = variable_get('uc_address_fields_weight', _uc_extra_fields_pane_getDefaultAddressFieldsWeights($form_part, $prefix));

  // Ubercart Addresses integration:
  // If a field 'address_select' exists, give this field the lowest weight, so that this field appears at first
  if (isset($form_part[$prefix . 'address_select'])) {
    $iLowestWeight = min($weights);
    $weights['address_select'] = $iLowestWeight - 1;
  }

  // Apply weight to fields
  foreach ($weights as $fieldname => $weight) {
    if (isset($form_part[$prefix . $fieldname])) {
      $form_part[$prefix . $fieldname]['#weight'] = $weight;
    }

    // Fieldtype can be a constant. In that case an extra field typed '#item' can be shown.
    if (isset($form_part[$prefix . $fieldname . '_i'])) {
      $form_part[$prefix . $fieldname . '_i']['#weight'] = $weight;
    }
  }
}