You are here

function uc_addresses_entity_property_info_alter in Ubercart Addresses 7

Implements hook_entity_property_info_alter().

File

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

Code

function uc_addresses_entity_property_info_alter(&$info) {

  // Explain address fields to the entity API.
  $fields = uc_addresses_get_address_fields();
  $properties =& $info['uc_addresses']['properties'];
  foreach ($fields as $key => $field) {
    if (isset($properties[$key])) {
      $properties[$key] = array_merge($properties[$key], $field);
    }
    else {
      $properties[$key] = $field;
    }
    $properties[$key]['getter callback'] = 'uc_addresses_field_get';
    if ($key != 'aid' || $key != 'uid') {
      $properties[$key]['setter callback'] = 'uc_addresses_field_set';
    }
  }

  // Special case for user, this should be mapped to 'user' instead
  // of 'uid' as noted on http://drupal.org/node/1021466.
  $properties['user'] = $properties['uid'];
  $properties['user']['label'] = t('User');
  unset($properties['uid']);

  // Expose default addresses of user.
  $info['user']['properties']['uc_addresses_default_shipping_address'] = array(
    'type' => 'uc_addresses',
    'label' => t('Default shipping address'),
    'getter callback' => 'uc_addresses_user_address_property_get',
  );
  $info['user']['properties']['uc_addresses_default_billing_address'] = array(
    'type' => 'uc_addresses',
    'label' => t('Default billing address'),
    'getter callback' => 'uc_addresses_user_address_property_get',
  );

  // Explain the attached addresses from uc_addresses on the Ubercart order.
  $info['uc_order']['properties']['uc_addresses_delivery_address'] = array(
    'type' => 'uc_addresses',
    'label' => t('!address_type (Ubercart Addresses)', array(
      '!address_type' => t('Delivery address'),
    )),
    'getter callback' => 'uc_addresses_uc_order_address_property_get',
  );
  $info['uc_order']['properties']['uc_addresses_billing_address'] = array(
    'type' => 'uc_addresses',
    'label' => t('!address_type (Ubercart Addresses)', array(
      '!address_type' => t('Billing address'),
    )),
    'getter callback' => 'uc_addresses_uc_order_address_property_get',
  );
}