My addresses currently display like this:

123 Main St
Beverly Hills California 90210
United States

Instead, I want them to display like this:

123 Main St
Beverly Hills, CA 90210

(No country, state is two-letter abbreviation, and comma between city and state)

It is non-obvious to me even where to begin to control this formatting. I see in the module there is a folder called "example", I wonder if I'm supposed to do something with that? I'm not afraid of writing some php to do the job but I don't know where to begin. Please help!

Comments

tvilms’s picture

Here's your question with some responses on StackExchange. It's a little more to go on:

http://drupal.stackexchange.com/questions/16232/how-to-hide-country-in-a...

userofdrupal’s picture

I found this api document page.

http://api.drupalhelp.net/api/addressfield/addressfield.module/group/add...

I think I might need to write a CTools plugin.

userofdrupal’s picture

anyone?

tvilms’s picture

Hi there. Wanted to close the loop on this. @overflowing, maybe you could still use some info. If not, I'll leave this here for posterity.

Here's what I did to control the display formatting. I made a new plugin, modeled off the existing "address.inc" file in the addressfield/plugins/format directory and saved the new plugin in the same directory. I reviewed the existing file and changed and/or commented out aspects of the display format that I didn't like. As a result, I was able to end up with a format that only shows city and state, with no street address or zip code fields. I named my plugin "citystate.inc" and modified the function calls accordingly.

You'll need to experiment a bit with the existing functions & logic, but no doubt you'll be able to get something working.

les lim’s picture

I just submitted a patch that could help make this easier:

#1541384: Provide regular theme function for displaying an address as an alternative to formatter plugins

Please chime in over there and see if we can get something like this in.

userofdrupal’s picture

@tvilms and @Les Lim I appreciate the followup will check these different methods out

funkeyrandy’s picture

how did you get commas to display?

okeedoak’s picture

Install Addressfield Tokens, then implement theme_addressfield_formatter__components($vars) in your template.php file. The last part of the function name "__components" corresponds to the "Address Components" format in Manage Display. In other words, each format has it's own function.

jhodgdon’s picture

bugster’s picture

for the comma to display you could edit address.inc
find the US section and add
$format['locality_block']['locality']['#suffix'] = ',';

for the abbreviation to show: edit address.inc, find the US section and add
$format['locality_block']['administrative_area']['#abbr'] = TRUE;

and also edit the addressfield.module
find the function _addressfield_render_address(&$format, $address)
and replace the if-else statement if (isset($child['#options'])) with

if (isset($child['#options'])) {
 // Expand options if necessary.
 if(isset($child['#abbr']) && $child['#abbr'] === TRUE)
   $child['#children'] = isset($child['#options'][$address[$key]]) ? check_plain($address[$key]) : ''; //state abbr
 else
   $child['#children'] = isset($child['#options'][$address[$key]]) ? check_plain($child['#options'] [$address[$key]]) : ''; //state fullname
}
else {
  $child['#children'] = check_plain($address[$key]);
}
mgifford’s picture

Under "Manage display" it looks like we should be able to find some "widget configuration" to use. However I don't see where this might be.

I have the option of enabling/disabling the default setting but I should be able to configure or view the widget configs if I am to know what "Use the same configuration as the widget" actually means.

Oh ya, and "Use the same configuration as the widget" is missing a '.'

rszrama’s picture

Status: Active » Closed (duplicate)

Address rendering itself is not configurable via the UI at the moment. It depends on properties of a renderable array generated by the various address field plugins that you toggle on in the checkboxes list when creating the address field. However, my commit / notes in #1427682-5: [API change] Make expanding an administrative area code to its full options list value optional directly address the original post but adding options / city comma suffix to fix U.S. addresses. The country is still there, but that's another animal... you might follow #1316788: Do not display country in address block if only one country option is available, and I'll address how to disable it from rendering when I add the developer documentation noted in #1267292: Document the user interface, API, and working with the form element. Because of those two issues, I'm going to close this one out as a duplicate.

colan’s picture

For what it's worth, there shouldn't be a comma after the city. See #2107705: Support different output formats, e.g. printed machine-readable vs. screen human-readable for details.