You are here

function uc_addresses_token_values in Ubercart Addresses 6

Same name and namespace in other branches
  1. 6.2 uc_addresses.module \uc_addresses_token_values()

Implementation of hook_token_values().

File

./uc_addresses.module, line 232

Code

function uc_addresses_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  if ($type === 'user') {
    $user = $object;

    // Retrieve default addresses for the given user from the database and
    // expand the token values of such.
    if (isset($user->uid) && $user->uid) {
      $aid = _uc_addresses_get_default_address_id($user->uid);
      if ($aid) {
        $address = (array) uc_addresses_address_load($aid, $user->uid);
        $exclude = array(
          'aid',
          'uid',
          'created',
          'modified',
        );
        foreach ($address as $key => $value) {
          if ($key === 'country') {
            $values['uc-addresses-default-' . $key . '-raw'] = uc_country_get_by_id($value);
            $values['uc-addresses-default-' . $key] = check_plain(uc_country_get_by_id($value));
          }
          elseif ($key === 'zone') {
            $values['uc-addresses-default-' . $key . '-raw'] = uc_zone_get_by_id($value);
            $values['uc-addresses-default-' . $key] = check_plain(uc_zone_get_by_id($value));
          }
          elseif ($key === 'created' || $key === 'modified') {
            $values += token_get_date_token_values($address[$key], 'uc-addresses-default-' . $key . '-');
          }
          else {
            if (!in_array($key, $exclude)) {

              // For some fields we don't need raw tokens.
              $values['uc-addresses-default-' . $key . '-raw'] = trim($value);
            }
            $values['uc-addresses-default-' . $key] = trim(check_plain($value));
          }
        }
      }
    }
  }
  return $values;
}