When you enable "full address" in the node views its formatted as follows:

street, zip code
city, state

instead of

street,
city, state, zip

also, i'm not sure where i can change the format of the 'province/state' field to use the code instead of the full name

Comments

swentel’s picture

Status: Active » Closed (fixed)

You can use a theme override of the 'theme_nd_location_address' function, that way, you can choose how you want to output the full address.

bewhy’s picture

Category: bug » support

sorry, I don't speak themer :) . . . I went into the nd.tpl.php file and re-ordered the fields in the address array. I came away with two problems:

1. I'd actually like to change it from province name to province code
2. the postal code isn't showing (as it was with the previous order)

So, i'm sure more information about this "theme overide" would help a bit.

(ps. I''ve changed this to a support request because simply there's actually nothing wrong with the code, but 'wrong' with the formatting of the [american] address)

bewhy’s picture

Status: Closed (fixed) » Needs work
swentel’s picture

Status: Needs work » Postponed (maintainer needs more info)

Ok, what you'll need todo is this: open template.php and copy the whole 'theme_nd_location_address' to this file. You need to rename the function to phptemplate_nd_location_address. You'll need to rebuild the cache. More info about theming overrides is found at http://drupal.org/node/173880.


function theme_nd_location_address($field) {
  // This is the original code, but you can do whater you want here.
  $address = array();
  if (!empty($field['object']->location)) {
    if (!empty($field['object']->location['street'])) {
      $address[] = check_plain($field['object']->location['street']);
    }
    $fullcity = array();
    if (!empty($field['object']->location['postal_code'])) {
      $fullcity[] = check_plain($field['object']->location['postal_code']);
    }
    if (!empty($field['object']->location['city'])) {
      $fullcity[] = check_plain($field['object']->location['city']);
    }
    $address[] = implode($fullcity, ' ');
    if (!empty($field['object']->location['province_name'])) {
      $address[] = check_plain($field['object']->location['province_name']);
    }
  }
  return implode($address, ', ');
}
swentel’s picture

Status: Postponed (maintainer needs more info) » Fixed
bewhy’s picture

Status: Fixed » Postponed

i'm pretty sure that i followed your instructions to the 't'. . . but then I got a white screen, yes, even when clearing the caches.

I think it would be easier for everybody (including myself) if the default was properly formatted instead of having to create work-arounds for it to display as one would expect it to (and I promise I had no intention to sound snarky or smart-mouthed in that statement)

bewhy’s picture

thanks for not letting me be lazy. . . I'm not sure if what i did is exactly kosher, but it works. This is exactly what I have in my template.php file now (yes, without the php tags):

function phptemplate_nd_location_address($field) {

  $address = array();
  if (!empty($field['object']->location)) {
    if (!empty($field['object']->location['street'])) {
      $address[] = check_plain($field['object']->location['street']);
    }
    $fullcity = array();
    if (!empty($field['object']->location['city'])) {
      $fullcity[] = check_plain($field['object']->location['city']);
    }
	if (!empty($field['object']->location['province_name'])) {
      $fullcity[] = check_plain($field['object']->location['province_name']);
    }

    $address[] = implode($fullcity, ' ');
    
	 if (!empty($field['object']->location['postal_code'])) {
      $address[] = check_plain($field['object']->location['postal_code']);
    }
  }
  return implode($address, ', ');
}

and it outputs this:
1439 South Street, Philadelphia Pennsylvania, 19146
instead of
1439 South Street, Philadelphia Pennsylvania, 19146

now I need to figure out how to shorten the province name to the province code

bewhy’s picture

Status: Postponed » Fixed

quick question though, how does one change the output of the province name to province code?

swentel’s picture

Don't know it by heart exactly, but what you can do is this:

  dsm($field['object']->location);

You need to install the devel module for dsm to work. I'm not sure if the province code is inside the location object, if not, you'll have to load it via the location_province_name($country, $province) function.

swentel’s picture

Status: Fixed » Closed (fixed)
bradezone’s picture

I was curious about this too. I tweaked my theme function as follows:

function mytheme_nd_location_address($field) {
return check_plain($field['object']->location['street']) . '<br />'
. check_plain($field['object']->location['city']) . ', '
. check_plain($field['object']->location['province_name']) . ' '
. check_plain($field['object']->location['postal_code']);
}

Just curious why such an odd order is used as the default? Is there some country where postal code comes before the city?

victoriachan’s picture

This is really an issue with nd_contrib. See http://drupal.org/node/900612

ryanfc78’s picture

I ran into this same issue and found a "easier" fix than this patch. Just go to location.tpl.php in the Location folder under Modules. Around line 16 you will see the postal code followed by city and province. Jut copy the lines of code for postal_code and move it below Province.

So it looked like this:

   <?php if (!empty($postal_code)): ?>
      <span class="postal-code"><?php print $postal_code; ?></span>
    <?php endif; ?>
    <?php if (!empty($city)): ?>
      <span class="locality"><?php print $city; ?></span><?php if (!empty($province)) print ', '; ?>
    <?php endif; ?>
    <?php if (!empty($province)): ?>
      <span class="region"><?php print $province_print; ?></span>
    <?php endif; ?>

and I changed it to this:

    <?php if (!empty($city)): ?>
      <span class="locality"><?php print $city; ?></span><?php if (!empty($province)) print ', '; ?>
    <?php endif; ?>
    <?php if (!empty($province)): ?>
      <span class="region"><?php print $province_print; ?></span>
    <?php endif; ?>
    <?php if (!empty($postal_code)): ?>
      <span class="postal-code"><?php print $postal_code; ?></span>
    <?php endif; ?>

This will put the postal code after the state/province.

tbw17’s picture

Thank you #13, simple solution and much appreciated!

schmook’s picture

#13 is a good solution. Thanks!

Just a note: you should move location.tpl.php to your theme directory. Otherwise, if you update the module in the future it will be overwritten.

bstrange’s picture

Issue summary: View changes

@schmook, while it is a good idea to put this in your theme directory; one would think that eventually they'd fix it... yet a year since your post and it's still there... go figure.
For me, I'd assume 'update' would include fixing the glaring layout error akin to putting the area code after the phone number :P

Gosh, I'm cranky tonight, guess I'm just irritated I am back on this thread years after the first time I came across this bug, don't mind me ;)

joyv’s picture

As a newbie, when I move this to the theme directory should I create a folder called "location" or where should I place it?

I am also running Omega 4 if that has an impact.

UPDATE: For Omega 4 place the file in the "Templates" directory of your theme and create a subfolder "Location" to help keep the files organized. Worked perfect!

dkhill’s picture

I am using the Garland theme, so I copied it to the root folder of my garland directory theme and the issue was resolved. The only thing else I was trying to do is move the "additional" field to fall right under the location name.
I guess I'll have to play with this piece of code.

Thanks for sharing this!

JimJS’s picture

Using logical operators to add the zip code to the proper location worked for me.

if (!empty($postal_code) && strtoupper($country) !== 'US'):
- and -
if (!empty($postal_code) && strtoupper($country) === 'US'):

I also had some format problems because of the use of class="region" in the printing of the $province variable. It appears that my theme use "region" as a class in many instances. By changing this to something else like "province-region" it kept the zip code in a proper order. I also looked at the location module's css and it did not have any instances of ".region".