You are here

function uc_addresses_preprocess_address in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 uc_addresses.module \uc_addresses_preprocess_address()

Prepare address fields for display.

Parameters

UcAddressesSchemaAddress $address: The address object.

string $context: The context in which the fields will be displayed.

Return value

array An array with fieldname => data.

3 calls to uc_addresses_preprocess_address()
template_preprocess_uc_addresses_list_address in ./uc_addresses.pages.inc
Prepares variables for one address.
uc_addresses_checkout_pane_address in ./uc_addresses.ubercart.inc
Callback for an address checkout pane.
uc_addresses_order_pane_address in ./uc_addresses.ubercart.inc
Callback for an address order pane.

File

./uc_addresses.module, line 593
Adds user profile address support to Ubercart.

Code

function uc_addresses_preprocess_address(UcAddressesSchemaAddress $address, $context = 'default') {

  // Build field list.
  $fields = array();
  $weight = 1;
  $handlers = uc_addresses_get_address_field_handler_instances($address, $context);
  foreach ($handlers as $fieldname => $handler) {
    if ($handler
      ->isFieldEnabled() && $handler
      ->checkContext()) {
      $value = $handler
        ->outputValue();
      if ($value !== '') {
        $fields[$fieldname] = array(
          'title' => $handler
            ->getFieldTitle(),
          'data' => $value,
          '#weight' => $weight++,
        );
      }
    }
  }

  // Set weight of address name (if available).
  if (isset($fields['address_name'])) {
    $fields['address_name']['#weight'] = -10;
  }

  // Address format.
  $fields['address'] = array(
    'title' => t('Address'),
    'data' => uc_addresses_format_address($address, $context),
    '#weight' => -1,
  );
  if ($context == 'order_view') {

    // Don't show address label when viewing the order.
    unset($fields['address']['title']);
  }

  // Allow other modules to alter the preprocessed address fields.
  drupal_alter('uc_addresses_preprocess_address', $fields, $address, $context);

  // Sort fields.
  uasort($fields, 'element_sort');
  return $fields;
}