Closed (fixed)
Project:
Address Field
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Jan 2011 at 16:12 UTC
Updated:
14 Mar 2013 at 01:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
damien tournoud commentedCommitted the attached patch.
Comment #2
damien tournoud commentedActually, we also need to add a "None" country to the subsequent elements, in order to make sure that the user can remove them.
Comment #3
damien tournoud commentedCommitted the attached patch.
Comment #5
tommychrisIf I select a default country, on every save there will be a new row, IF the user not select the 'None'. So maybe only the first instance has the default value, and the other instances get the 'None' value.
Comment #6
tommychrisI cahnged this in addressfield.module line 328:
Comment #7
mrbrookman commentedcan somebody please commit the patch of ThommyChris in post #6.
It seems a better solution than the current behaviour of the field.
Patch attached
Comment #8
cotto commentedHere's an updated version of the patch. I'm not 100% sure if this is the right place to put that kind of code, but it seems to work with 7.x-1.x.
Comment #9
mikeytown2 commented#8 has bad logic
Comment #10
R.J. Steinert commentedWith HEAD (contains Damien's patch), save a node with two addresses, then try to delete the second address by deleting all of the fields for that address and choosing "none" for the country. The second address will persist as a location with only "United States" as the country (confirmed by checking devel output).
Patch in #7 I don't think was generated from HEAD so applying will fail.
Using #8, second locations country always results in "none" even if a country is chosen.
Debugging now...
Comment #11
mikeytown2 commentedI've done this in a different module for now. Our field is called "additionallocation" and the node type is "profile"
Comment #12
R.J. Steinert commentedI see there has been some major refactoring of addressfield_field_widget_form() since http://drupalcode.org/project/addressfield.git/blob/c9414f98f5b0a4f27f2d.... Looks like we're kind of starting over on this one.
Comment #13
R.J. Steinert commented@Mikeytown I just tested your code on my own installation (modifying the field machine names) and I'm seeing good results. Did you go with that approach because it was quick and easy or because of a particularly difficult barrier to fixing in the addressfield module?
Comment #14
mikeytown2 commentedQuick and easy. Getting a proper fix shouldn't be that hard to do; putting the logic in hook_node_presave might be the right idea as we need to know about all deltas in this field; removing ones that only have the country set. My logic is quick as I only check if the state (administrative area) is empty.
Comment #15
R.J. Steinert commentedI think hook_entity_presave would be better for cases when an addressfield is on something that isn't a node. I'm not sure if there is a generic way to load the field definitions for entities though. We need to check which fields are addressfields so we know which fields on the entity being saved to modify. Perhaps a presave hook is not our best option.
Comment #16
mikeytown2 commentedDoing a mini code audit here and I have a modified version of #8 applied. I've attached that here for now, not sure if it is needed or good/bad.
Comment #17
fearlsgroove commentedHere's a generified version #11, applied to hook_entity_presave in addressfield. Not extensively tested, but it seems to work fine on a content type with both one addressfield with cardinality 1 and an unlimited addressfield.
Comment #18
mikeytown2 commentedNew patch based off of #16 & #17.
Note that this no longer creates a blank entry.
Comment #19
johnvI am not sure what the subject of this issue is ATM.
OP is fixed in #3.
Do patches resolve "An address is generated, even if user does not enter an address" ?
If so, we might better continue in #1844846: Make Addressfield optional, (even if country is required) .
That contains similar patches, but using hook_field_presave() instead of hook_entity_presave() , and has a better description.
hook_field_presave is more performant, and you can check against the default value in the field instance settings, instead of checking only the empty values.
Comment #20
johnvI'm pretty sure that #1844846: Make Addressfield optional, (even if country is required) is the same.
Resetting status to fixed, as per #3, fixing the original issue. Please reset the status if you think it is not.