theme_addresses problem
vasike - May 28, 2009 - 06:21
| Project: | Addresses |
| Version: | 6.x-1.05 |
| Component: | User interface |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs review |
Description
empty values for firsts addresses fields in format => empty line in html
generated by theme_addresses function in addresses.inc
// Call token module to replace all tokens to their right value. Also,
// use 'adr' microformat
$format_address = '<dl class="adr">'.
token_replace($format_address, 'addresses_adr', $afields, '!', '') .'</dl> ';
// Besides being the Drupal Address info,
// its possible to be used by hCard and VCard (if a address name was provided)
$format_address = '<div class="vcard">'.
token_replace($format_address, 'addresses_general', $afields, '!', '') .'</div>';solution:
/**
* Generates HTML for the passed address.
*
* @ingroup themeable
* @param $afields
* Array. A single address with the following fields (generally, but it can have more):
* - 'street' => A string representing the street
* - 'additional' => A string for any additional portion of the street
* - 'city' => A string for the city name
* - 'province' => The standard postal abbreviation for the province
* - 'country' => The two-letter ISO code for the country of the address (REQUIRED)
* - 'postal_code' => The international postal code for the address
*/
function theme_addresses($afields) {
// If all fields are hidden, return ''
if (empty($afields)) {
return '';
}
// Get the proper address format
if (!empty($afields['country'])
and !$format_address = variable_get('addresses_format_'. $afields['country'], '')) {
// Load country specifice code .inc file if it exists.
// For example, if country_code for U.S. == 'us', load 'addresses.us.inc'
include_once drupal_get_path('module', 'addresses') .'/countries/'. $afields['country'] .'.inc';
// If the country has an preset address format
$function = 'addresses_address_format_'. $afields['country'];
if (function_exists($function)) {
$format_address = $function();
variable_set('addresses_format_'. $afields['country'], $format_address);
}
}
// If still no proper address format, use the United States format
if (empty($format_address) and !$format_address = variable_get('addresses_format_default', '')) {
include_once drupal_get_path('module', 'addresses') .'/countries/us.inc';
$format_address = addresses_address_format_us();
variable_set('addresses_format_default', $format_address);
}
// Call token module to replace all tokens to their right value. Also,
// use 'adr' microformat
$format_address = token_replace($format_address, 'addresses_adr', $afields, '!', '');
// Besides being the Drupal Address info,
// its possible to be used by hCard and VCard (if a address name was provided)
$format_address = token_replace($format_address, 'addresses_general', $afields, '!', '');
// Replace the new lines for HTML line breaks AND remove
// all empty lines
$format_address = explode("\n", $format_address);
foreach (array_keys($format_address) as $line) {
$format_address[$line] = trim($format_address[$line]);
if (empty($format_address[$line])) {
unset($format_address[$line]);
}
}
$format_address = implode('<br/>', $format_address);
$format_address = '<dl class="adr">'.
$format_address .'</dl> ';
// Besides being the Drupal Address info,
// its possible to be used by hCard and VCard (if a address name was provided)
$format_address = '<div class="vcard">'.
$format_address.'</div>';
// Add the CCS
drupal_add_css(drupal_get_path('module', 'addresses') .'/addresses.css');
return $format_address;
}
#1
Here is a patch for the above.
#2
Uploaded new patch that also prevents empty divs and dl' being created when ALL address fields are empty:
i.e.:
<?php
$format_address = '<dl class="adr">'.
$format_address .'</dl> ';
// Besides being the Drupal Address info,
// its possible to be used by hCard and VCard (if a address name was provided)
$format_address = '<div class="vcard">'.
$format_address.'</div>';
?>
is now:
<?php
if (!empty($format_address)) {
$format_address = '<dl class="adr">'.
$format_address .'</dl> ';
// Besides being the Drupal Address info,
// its possible to be used by hCard and VCard (if a address name was provided)
$format_address = '<div class="vcard">'.
$format_address.'</div>';
}
?>
#3
could be my problem when the user dont fill all the information i get some blank space with
the code i get is something like:
<dt>Address</dt><dd><div class="vcard"><dl class="adr"><br/></dl> </div></dd>
<p id="content-profile-view"> <h3 class="content-profile-title" id="content-profile-title-dj">
you can see the problem in this page
http://www.freelancedj.com/dj-glorious
it suppose the address field are bottom of all other cck fields, but at top of the panels i get the adreess title code.