Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is related to #968112: Allow addressfield to be optional but not dependent on it.
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedI think that's a good idea, but we should keep it optional. I merged the attached.
Comment #2
ezheidtmann CreditAttribution: ezheidtmann commentedThanks for adding this, Damien. It's exactly what I need. But the patch has no effect in "render" mode because the options list is not restricted in that mode.
The attached patch fixes this by moving the relevant code out of the "if(mode == 'form')" block. Is this the right way to do it?
Comment #3
ezheidtmann CreditAttribution: ezheidtmann commentedBumping, and changing the title to more accurately describe the latest issue.
My rationale for this change is that if a site makes just one country available to its users, then that country should be implied in all contexts where addresses are used. My use case is a teacher's union in the US -- all addresses are for members or schools within a district. We don't need "United States" printed on every address label.
Comment #4
orlitzky CreditAttribution: orlitzky commentedI applied the patch in #2 because I need the same feature. Regardless of whether or not that's The Right Way To Do It, I think it's the way the "hide country" feature should work.
Comment #5
markabur CreditAttribution: markabur commentedTested #2 and it works.
Comment #6
andrewbelcher CreditAttribution: andrewbelcher commentedI think it should be changed to a bug as (especially with the display settings), it is expected behaviour for it to be hidden.
As instance settings count potentially change, is it not better to make the adjustment in the address-hide-country plugin so that it doesn't break previously saved fields? So changing the #access check to something like the attached patch...
That means that if there is only one country, it will ignore rendering it unless the saved country isn't in the allowed list (ie is different from normal), in which case it will show it.
Comment #7
cesareaugusto CreditAttribution: cesareaugusto commentedIs this patch backported to the official release?
Comment #8
klonosThe improved logic behind #6 is perfect! This really made my day Andrew ;)
PS: ...while at it, there's a minor typo in address-hide-country.inc (doesn't deserve its own issue):
...should be:
("the" - not "then")
Comment #9
daveparrish CreditAttribution: daveparrish commentedRerolled #6 with unix whitespace. For me, this is important for drush make patches to work. http://drupal.org/coding-standards#indenting
Comment #10
Loube CreditAttribution: Loube commentedI am having trouble applying either patch #6 or #9. I am fairly new to git and I got this message when I tried to apply either patch.
"can't find file to patch at input line 5"
Comment #11
orlitzky CreditAttribution: orlitzky commentedYou probably just need to supply "-p1" on the command line. Example:
What's going on is, if you look at the top of the patch file, you'll see paths that look like
a/foo
andb/foo
. Thea
andb
are really just dummy directories; if you're sitting in the directory you'd like to patch, you don't need them. So, you want to strip them off. The "-p1" argument to patch simply means "strip off the first path component."Comment #12
Loube CreditAttribution: Loube commentedmjorlitsky,
Thank you for your help. I was able to use Git to install the branch 7.x-1.x on my local machine.
(I was a little confused because the repository showed no dev version, even though the dev version is shown on the project page. The dev is also the version that this thread is shown under. But the 7.x-1.x version that you showed in your example was in the repository and not on the project page. )
I am using a CygWin teminal with Git Bash. It says: sh:exe" wget command not found. I have searched all over the web and I haven't figured out how to have wget work. So I haven't been able to use Git to get the patch.
Comment #13
orlitzky CreditAttribution: orlitzky commentedI was using wget to download the patch, but it was just to make the command-line example clearer. Where I used wget, you can open your browser and download the patch file manually into the
addressfield
directory.The rest should work the same.
Comment #14
Loube CreditAttribution: Loube commentedOkay thanks. I wondering about that - if I could just put the patch in the directory. I ended up putting the patch in addressfield/plugins/format dir because I continued to get the error message about line 5. So I tried to patch with it in the same dir as the .inc but got this message: patch**** malformed patch at line 22.
Comment #15
orlitzky CreditAttribution: orlitzky commentedWell, if you re-run the cygwin setup, you should be able to install wget. Then you can run the example exactly =)
Comment #16
dlshannon CreditAttribution: dlshannon commentedI've installed 7.x-1.0-beta3, checked the new "Hide the country when only one is available" and yet the one country (United States) is still rendered in the address field of the nodes. Am I misunderstanding the nature of this enhancement?
Comment #17
orlitzky CreditAttribution: orlitzky commentedIf I remember correctly, the checkbox was always there. It just doesn't work the way you expect it to without this patch. Did you apply the patch?
Comment #18
dlshannon CreditAttribution: dlshannon commentedI'm pretty sure that checkbox didn't exist in beta2. I've been writing a tutorial for fellow newbies and I just documented the options on that page last week while using beta2.
I didn't install a patch but the beta3 release notes indicate that the patch is included in beta3. I installed beta3 today.
Thank you so much for helping with this.
Comment #19
orlitzky CreditAttribution: orlitzky commentedOh, you're right.
From the release notes, it looks like the patch in comment #1 was merged. That adds the checkbox, and checking the box makes the country field go away when you're creating stuff. But as comment #2 points out, it has no effect on the display of the country field.
In my opinion comment #9 has the best fix so far.
Comment #20
dlshannon CreditAttribution: dlshannon commentedOkay, thanks. I'll continue to use CSS to set the display of the Country field to "none" until this is included functionality.
For the benefit of any other newbies that may read this, the following works for me from within my Bartik sub-theme:
.field-type-addressfield .country {display: none;}
Comment #21
Sborsody CreditAttribution: Sborsody commentedPatch in #9 works fine for me. What a relief! It's embarrassing to see the country show up when showing a client even though it was configured not to show. (This aspect is a bug since the original feature request was fulfilled.)
Comment #22
AaronBauman#9 works great.
RTBC++
Comment #23
liquidcms CreditAttribution: liquidcms commentedtried patch form #2, it doesnt seem to do anything that i can see
tried patch from #9, but what is this for?? it is trying to patch the file: address-hide-country.inc, what is that? so i took code from that patch and manually added to address.inc, same result.. no visible affect
Comment #24
AaronBaumanThis file does not exist in the latest beta.
The patch worked fine for me against the latest dev -- are you sure you're using 7.x-1.x-dev with datestamp 1323734458 (2011-12-13)?
Comment #25
liquidcms CreditAttribution: liquidcms commentedyup, my bad..i had beta2, latest -dev is pretty old so i grabbed beta3 (not sure how -dev can be older than a rel; i think a bug in the new GiT system)
patch in #9 now applies cleanly and feature seems to be working as expected.. :)
Comment #26
makbul_khan8 CreditAttribution: makbul_khan8 commentedHi
This is a solution for hiding only country field from address block
Step 1. Register a plugins folder in our module
Step 2. Create actual folder plugins and put folder format there
Path: sites/all/modules/custom/custom_module/plugin/format/
NOTE: custom_module is a name of your custom module
Step 3. Create file and put inside format folder
custom_module-address-row.inc
Step 4. Flush your cache
Under Manage fields you will get an extra check-box field, enable it and its done.
Reference: http://blog.artemshymko.com/format-your-address-field-correctly
Thanks
Comment #27
Alex Bukach CreditAttribution: Alex Bukach commentedIf Hide the country when only one is available option is enabled in addressfield display settings (either directly or by checking Use the same configuration as the widget there and enabling the same option in field settings), and a single country only is marked in countries list of the field instance, the country still displays. I've implemented a patch to fix this issue.
Comment #28
johnv@ #27, your patch is not valid. it does the same as #9, but in another, unrelated file, and is more expensive.
Above all, it removes an important feature from #9, which might have happened in your system:
#9 does NOT hide the country if the entered country is different from the (only) default country. (This can be the case if you first enter some addresses, and later set the only default country and the checkbox.)
Comment #29
johnv@#26, what is the purpose of your proposal? is it an alternative way for the same issue, which is resolved elegantly in #9?
Comment #30
johnvSetting patch in #9 back to RTBC (approved by #19, #21, #22, #23-25, and me), since #26, #27 do not improve #9.
Comment #31
dalinThis patch is just a very small clean-up on the RTBC #9:
- Added linebreak in
} else {
- Use the preferred isset() rather than array_key_exists().
Comment #32
kiwimind CreditAttribution: kiwimind commentedThis patch works fine for hiding the output on a node, but when the field is being output inside a vertical tab, the tab still renders empty, which would suggest that there's still something being left behind.
If a tab has no elements to render it doesn't appear, which is not the case if an addressfield field is present, even when empty.
Comment #33
dalinI don't think that issue is specifically related to countries. It's a common issue with several field types, addressfield may be adding a wrapper div or something.
Comment #34
rszrama CreditAttribution: rszrama commentedI agree with andrewbelcher's approach and appreciate all the effort that has gone into re-rolling it and reviewing it. I had to manually apply it due to changes I committed to this function earlier today, but it's working as expected (even for a legacy address using a different country value than the current field instance settings make available).
Agreed w/ respect to the vertical tab; that sounds like something happening upstream, perhaps due to our markup wrappers or some other unknown incompatibility.
Commit: http://drupalcode.org/project/addressfield.git/commitdiff/39ff714
Comment #35
kiwimind CreditAttribution: kiwimind commentedOk, thanks Ryan, might open another issue in that respect then to see what we can do about the vertical tab incompatability.
Thanks for all the hard work on this.
Comment #36
deanflory CreditAttribution: deanflory commented2013-May-08 dev version with the #31 patch (addressfield-hide-country-render-1316788-31.patch) produces this fail:
Is this fixed in the latest release (beta4 or dev) and I'm just not seeing where the decided solution was presented? Any help would be appreciated.
Comment #37
rszrama CreditAttribution: rszrama commentedPer my comment #34, I cleaned this up and committed it. It's part of the beta4 release.
Comment #38
deanflory CreditAttribution: deanflory commentedSorry, comment innundation here, was looking for a fix for the "need a -None- for country", sorry. Thanks!
Comment #39
rolfmeijer CreditAttribution: rolfmeijer commentedI might not understand the complications or specifics of this issue and I really appreciate the hard work that is gone into this, but I don’t think it is really fixed. When I install this patch, click the don’t display-checkbox the title of the field is still displayed if I leave all fields empty. In the outputted source code an empty (country) field is rendered. So it seems it is not really empty, otherwise no field would display (and no title along with it).
This might be related to the vertical tabs issue mentioned in #32.
The HTML that is rendered is:
Comment #40
rszrama CreditAttribution: rszrama commentedThat's a separate issue, and it's more or less working as designed. The field has a value, so Drupal expects the rendering process to produce at least some output. Even though our display formatter settings allow you to hide a part of a country field value when rendered, Drupal has already made the decision that the field has a value, and we can't come back later in the render phase and say it isn't the case. You might be able to follow along the issue to make the "empty value" conditions configurable.
Comment #41
rolfmeijer CreditAttribution: rolfmeijer commentedI see, that is an insightful explanation.
Comment #42
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedJust wanted to add a conclusion to this thread so that people don't have to read it all like I did to understand what they need to do.
If you only have one country and you would like to hide the country block from your form
here is what you need to do:
Upgrade to at least beta4
Go to Store >> Client profiles >> Profile types
There you might have two profiles such as Billing info and Shipping info.
Go to the Manage fields screen and then edit the address field.
Select your single country in the multiple select of available countries.
Finally check the box "Hide the country when only one is available".
Comment #44
anouJust another tip so none will loose time like I did. From the
address-hide-country.inc
fileI just needed to make the field required and the country field disappeared. ;-)