You are here

function _uc_extra_fields_pane_getDefaultAddressFieldsWeights in Extra Fields Checkout Pane 6.2

_getDefaultAddressFieldsWeights() Get the default weight settings for the address fields.

These settings will be used as a default value for variable_get('uc_address_fields_weight'). Because the contents of this setting will be called on several places, a general function is used to get the default settings.

If the fields don't have the #weight-attribute then the default $iWeight will be considered the weight of the field, this value will be increased for each field.

@access private

Parameters

array $fields:

string $prefix: On some forms the field names are prefixed, for example on the checkout forms where the fields names are prefixed with 'delivery_' and 'billing_' The settings are saved for the fields without the prefix, so we need to load the settings without the prefix.

Return value

array $aWeightFields

2 calls to _uc_extra_fields_pane_getDefaultAddressFieldsWeights()
_uc_extra_fields_pane_applyWeights in includes/weights.inc
_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.
_uc_extra_fields_pane_weight_uc_store_address_fields_alter in includes/weights.inc
_uc_extra_fields_pane_weight_uc_store_address_fields_alter() Adds option to order address fields by adding a weight field

File

includes/weights.inc, line 135
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_getDefaultAddressFieldsWeights($fields, $prefix = '') {

  // Get all available fields for the weight
  $aWeightFields = array();
  $iWeight = -31;
  foreach (element_children($fields) as $fieldname) {
    $iWeight++;

    // Substract prefix from fieldname, we don't want the prefix
    // saved into the default weight settings
    $fixedfieldname = $fieldname;
    if (strlen($prefix)) {
      if (strpos($fieldname, $prefix) === 0) {
        $fixedfieldname = substr($fieldname, strlen($fieldname));
      }
    }
    if (isset($fields[$fieldname]['#weight'])) {
      $aWeightFields[$fixedfieldname] = $fields[$fieldname]['#weight'];
      $iWeight = $fields[$fieldname]['#weight'];
    }
    else {
      $aWeightFields[$fixedfieldname] = $iWeight;
    }
  }
  return $aWeightFields;
}