function uc_addresses_format_address in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 uc_addresses.module \uc_addresses_format_address()
Format an address by using tokens.
Parameters
UcAddressesAddress $address: The address object.
string $context: The context in which the address will be displayed.
Return value
string A formatted address.
7 calls to uc_addresses_format_address()
- UcAddressesAddress::label in class/
UcAddressesAddress.class.php - Returns address name if given.
- UcAddressesTestCase::assertAddressLabel in tests/
UcAddressesTestCase.test - Pass if an address label is found on the page.
- UcAddressesTestCase::assertNoAddressLabel in tests/
UcAddressesTestCase.test - Pass if an address label is NOT found on the page.
- uc_addresses_form_process_select_address in ./
uc_addresses.module - Element process hook for an selectable address field.
- uc_addresses_preprocess_address in ./
uc_addresses.module - Prepare address fields for display.
File
- ./
uc_addresses.module, line 1955 - Adds user profile address support to Ubercart.
Code
function uc_addresses_format_address(UcAddressesAddress $address, $context = '') {
$country_id = $address
->getField('country');
$format = uc_addresses_get_address_format($country_id);
drupal_alter('uc_addresses_format_address', $format, $address, $context);
// Replace tokens.
$address_string = token_replace($format, array(
'uc_addresses' => $address,
));
// Clean-up address string.
$address_string = strtr($address_string, array(
"\n" => '<br />',
));
$address_string = strtr($address_string, array(
"\r" => '',
));
$match = array(
'`^<br( /)?>`',
'`<br( /)?>$`',
'`<br( /)?>(\\s*|[\\s*<br( /)?>\\s*]+)<br( /)?>`',
'`<br( /)?><br( /)?>`',
'`<br( /)?>, N/A`',
);
$replace = array(
'',
'',
'<br />',
'<br />',
'',
'',
);
$address_string = preg_replace($match, $replace, $address_string);
switch ($context) {
case 'token':
case 'checkout_review':
case 'order_view':
// Respect Ubercart capitalize address setting.
if (variable_get('uc_order_capitalize_addresses', TRUE)) {
$address_string = drupal_strtoupper($address_string);
}
break;
}
return $address_string;
}