Reviewed & tested by the community
Project:
Address Field
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Apr 2012 at 01:47 UTC
Updated:
12 Mar 2017 at 15:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
les limHere's a patch that implements the above suggestion. The actual
theme_addressfield_address()function provided here is extremely basic and was built with US addresses in mind. This should probably be expanded, but the key feature here to have something that can be overridden in the first place.Comment #2
les limChanging status.
Comment #3
thirdboxcar commentedThank you, works perfectly for my needs!
Comment #4
amarcus commentedAlso, look at the addressfield_tokens module. It provides several theme functions:
Comment #5
RobW commentedI'm looking for this too so I can easily theme with microdata (not microformats, which others are working on a field formatter for I believe). Will test the patch, thanks for starting on this Les Lim.
Comment #6
mrweiner commentedI had this working on a local dev version of my site running 7.12, but after uploading it to the server, with version 7.14, this theme function stopped working. It's not even displaying in the list of display format options. Any suggestions?
Comment #7
les limmrweiner: try clearing your caches.
Comment #8
mrweiner commentedI've cleared my caches multiple times and have also ran update.php as somebody else suggested. I'm quite baffled.
Comment #9
rich.3po commentedAgree that themeing address fields is far more convoluted than it needs to be.
For the time being, the addressfield_tokens approach suggested in #4 worked well for me. You can set the field formatter to 'One line' (in my case, in Views), then you have the option to override theme_addressfield_formatter__linear() if the default markup is not quite right.
Cheers
Comment #10
askibinski commentedpatch works perfectly, thanks!
Comment #11
infines commentedComment #12
joelcollinsdc commentedThis patch is like an island of simplicity emerging from a sea of complexity. Thank you.
Comment #13
big_smile commentedHow do you use this patch?
I have installed the patch and I know it is working, because in Display Options, Theme Function appears under format.
I then have copied the function my theme and changed theme to MYTHEMENAME (see code below). However, the changes do not appear to pick up (I have cleaned the cache):
Comment #14
les lim@big_smile: make sure you've got the field display set to "Theme function" in the entity's "Manage display" settings. While you're there, check to see that you're setting it for the right display mode - it's easy to set it only for "Default" without realizing that you might have "Teaser" and "Full mode" display modes overriding that.
Comment #15
big_smile commented@Les Lim, I've checked very carefully, it still doesn't work.
Is
MYTHEMENAME_addressfield_address($variables)the correct function use?Thanks for any help that can be offered.
Comment #16
acbramley commentedWow this is just what I was looking for, I'm rendering the address into a CSV and the functions and markup that the default formatter was ouputting just weren't working. I then went to happily override this output as I usually would and couldn't believe how complex this is implemented. This patch provides a great way for not only overriding the default funcitonality, but also programmatic rendering of the address.
Comment #17
acbramley commentedOk, I had a bit of trouble with overriding the theme function but I got there in the end. I went through the following things that didn't work before coming to my solution:
1) Tried using MYTHEME_addressfield_address in the template.php file of my front-end theme. This didn't work as I need it in the admin theme as well.
2) Tried using MYMODULE_addressfield_address in MYMODULE.theme.inc this didn't work either
3) Tried using MYMODULE_addressfield_address in MYMODULE.module again...
Finally, I implemented hook_theme_registry_alter() and this worked a charm. BUT there were some issues, I couldn't seem to have my themeing function in a different file (i.e MYMODULE.theme.inc) so this is what I came out with:
All done in my_module.module
Hope this helps others.
Comment #18
crizThis patch works for me but misses some variables in the default output (like city or organisation).
Anyway, having such a theme function is crucial, as the generated html by addressfield module is complex and hard to work with. For example I had a lot of troubles in commerce order notification e-mails using this module for shipping and invoice addresses. Also one of my clients had some issues copying the addresses from commerce backend to texteditors, because of the generated html.
To sum it up: Being able to adopt the html easily using a theme function would be very important.
Comment #19
rudiedirkx commentedYou could write
as
and
All fixed in new patch attached.
I've also added a formatter setting (
subformatter) so you can choose a formatting method you can then use in your custom theme functiion. WIth that, you can more easily specify your theme function, for instance:@criz ALL variables are sent to the theme function, the way they're named in addressfield. You're looking for
locality(city) andorganisation_name. You can see all availables inaddressfield_theme().Comment #20
rudiedirkx commentedComment #21
crizHad to apply this patch again after update to latest kickstart 7.x-2.13. This is just a notice that the patch from #19 works for me using addressfield 7.x-1.0-beta5.
Comment #22
giorgoskI think https://drupal.org/project/addressfield_tokens
solves most theme requirements out of the box
you should try it
but if not it has already implemented some theme functions for more custom solutions
Comment #23
rudiedirkx commentedI can't make with addressfield_tokens what #19 makes out of the box. I expected tokens in a field formatter, but there's nothing there...
This really needs to get in.
Comment #24
jenlamptonLooks like @criz meant to mark this one RTBC in #21.
Comment #25
gaëlgI can confirm it works well.
Comment #26
monstrfolk commentedUpdated patch to include country.
Added long country and administrative_area names.
Administrative_area long name only available if country is stored.
Comment #27
monstrfolk commentedIn some cases addressfield.administrative_areas.inc does not load. Had to include once.
Comment #28
monstrfolk commentedFixes Notice: Undefined variable: postal in theme_addressfield_address() (line 367 of /sites/all/modules/addressfield/addressfield.module).