You are here

function hook_uc_addresses_preprocess_address_alter in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.api.php \hook_uc_addresses_preprocess_address_alter()

This hook allows you to alter the address field listing before it's being displayed.

Examples of where the addresses can be listed:

  • the address book
  • the checkout review page
  • order view pages

Parameters

array $fields: An array containing the field data like this:

  • fieldname (array):

    • title => field title (string)
    • 'data' => field value (string)
    • '#weight' => weight (int)

UcAddressesAddress $address: The address object

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

  • address_view: the address book
  • checkout_review: the checkout review page
  • order_view: order view pages

Return value

void

1 invocation of hook_uc_addresses_preprocess_address_alter()
uc_addresses_preprocess_address in ./uc_addresses.module
Prepare address fields for display.

File

./uc_addresses.api.php, line 176
These hooks are invoked by the Ubercart Addresses module. @todo more documentation needed for hook_uc_addresses_field_handlers(). @todo Document the rest of the API.

Code

function hook_uc_addresses_preprocess_address_alter(&$fields, $address, $context) {

  // Example 1: add extra data in case this is the default shipping address.
  if ($address
    ->isDefault('shipping')) {
    $fields['mydata'] = array(
      'title' => t('Title'),
      'data' => t('Default shipping address'),
      '#weight' => 1,
    );
  }

  // Example 2: move my own field to the top.
  if (isset($fields['myfield'])) {
    $fields['myfield']['#weight'] = -20;
  }
}