You are here

function template_preprocess_uc_addresses_address_book in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 uc_addresses.pages.inc \template_preprocess_uc_addresses_address_book()

Prepares variables for address book.

Parameters

array $vars: An array with the following:

Return value

void

File

./uc_addresses.pages.inc, line 72
Page callbacks for viewing, adding, editing, and deleting addresses.

Code

function template_preprocess_uc_addresses_address_book(&$vars) {

  // Initialize variables.
  $vars['options'] += array(
    'add_link' => FALSE,
  );
  $vars['add_address_link'] = NULL;
  $vars['other_addresses'] = array();
  $vars['default_billing_address'] = NULL;
  $vars['default_shipping_address'] = NULL;

  // Find out which addresses are default addresses and which are not.
  $address_book = $vars['address_book'];
  foreach ($vars['addresses'] as $aid => $themed_address) {
    $address_object = $address_book
      ->getAddressById($aid);
    if ($address_object) {
      $vars['other_addresses'][$aid] = $themed_address;
      if ($address_object
        ->isDefault('billing') && variable_get('uc_addresses_use_default_billing', TRUE)) {
        $vars['default_billing_address'] = $themed_address;
        unset($vars['other_addresses'][$aid]);
      }
      if ($address_object
        ->isDefault('shipping') && variable_get('uc_addresses_use_default_shipping', TRUE)) {
        $vars['default_shipping_address'] = $themed_address;
        unset($vars['other_addresses'][$aid]);
      }
    }
  }

  // Setup odd/even for the other addresses.
  $count = 0;
  foreach ($vars['other_addresses'] as $num => $row) {
    $vars['row_classes'][$num][] = $count++ % 2 == 0 ? 'odd' : 'even';
  }

  // Setup admin links.
  if ($vars['options']['add_link']) {
    $vars['add_address_link'] = l(t('Add a new address'), 'user/' . $address_book
      ->getUserId() . '/addresses/add', array(
      'attributes' => array(
        'class' => 'address-link add-address-link',
      ),
    ));
  }
}