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.
Just upgraded to 7.x-1.0 and my ability to set the token default values for the address field components is gone. In the past version, when editing an addressfield field an example of what the form would look like would appear as you adjusted component settings, country available, single name, etc. This example form would allow the editor to fill each with tokens to display saved user data. Very useful for commerce checkouts since it would prefill the address for returning logged in customers.
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedYou can now only set the default country.
The other defaults were removed in #2392863: Remove the default values instance setting, introduce a default country instance setting, since they didn't work properly for optional fields, and for people trying to set defaults via code.
You can recreate the same functionality using hook_addressfield_default_values_alter().
Comment #2
cybermache CreditAttribution: cybermache commentedThanks for letting me know there wasn't anything wrong on my development install. It saddens me that this happened since it was so easy just to use address tokens to populate address field components with existing user data. You can't make everyone happy, I know, and making the module work better for most is the best path.
So with this change, my only option to reproduce my previous ability is to write a custom module? Besides the example in the included addressfield.api.php file, is there other documentation on how this new hook works?
Comment #3
bojanz CreditAttribution: bojanz commentedYes, custom module. There's no additional documentation, should be straightforward, post your final code here and we'll extend our example if necessary.
Comment #4
aitala CreditAttribution: aitala commentedI'd be interested in seeing @cybermache 's solution...
Eric
Comment #5
cybermache CreditAttribution: cybermache commentedHere is what I came up with. Of course it is specific to my needs as it calls/queries to a specific field/table name. Ideally it would provide a admin UI where one could select the address field and fill the fields with the tokens desired. At first I also had this module fix the country value but took it out because it seemed redundant. I realize
$GLOBALS['user']
might not be the best to use here as I believe it is being avoided in D8. Please share any mods if you'd liked to. Hope it helps.sites/all/modules/custom/field_defaults/field_defaults.info
sites/all/modules/custom/field_defaults/field_defaults.module