Closed (fixed)
Project:
Location
Version:
6.x-3.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Feb 2009 at 00:15 UTC
Updated:
23 Aug 2012 at 08:23 UTC
Jump to comment: Most recent file
Comments
Comment #1
alexevasion commentedOK, I've done more research and found that this issue has been broached before. However, all I have found are "crude hacks" of the 5.1 module. Is there something more elegant available for 6.3, or does anyone have an appropriate code snippet that will accomplish it in this version? i.e.
AFTER
function location_form($fields = array(), $prefilled_values = array(), $required_fields = array(), $suppressed_values = array(), $description = '', $function = NULL) {
if (count($fields) == 0) {
$fields = array('name', 'street', 'city', 'province', 'postal_code', 'country');
}
ADD
//Get default user profile location
$user_locations = location_load_locations('user', $GLOBALS["user"]);
$default_user_location = $user_locations['location'];
And then in the appropriate place in the form description use something like
REPLACE
'#default_value' => isset($prefilled_values['name']) ? $prefilled_values['name'] : '',
BY
'#default_value' => isset($prefilled_values['name']) ? $prefilled_values['name'] : $default_user_location['name'],
This snipped above would prepopulate "name" field of the address.
Use this to alternate city, postal code, country etc. fields in analogous fashion.
Comment #2
alexevasion commentedAnyone? Any help would be appreciated. Thanks, ALEX
Comment #3
futuresoon commentedI'm exploring hook_form_alter for this, but I dunno if it can be done that way yet.
Comment #4
alexevasion commentedPlease let me know if you have any success!
Comment #5
futuresoon commentedApparently instead of hook_form_alter, it's hook_locationapi. My only trouble now is getting access to $user->location, which seems to exist according to devel module, but I don't see it when I do
global $user; print_r($user);If you solve that before me, then let me know and I should soon have some working code to fill in a node's location fields with the author's location information from their profile.
Comment #6
futuresoon commentedYeah so I realized (mostly by asking merlin) that global $user isn't the full $user object. So now I have it worked out in principle:
1) make a module that implements hook_locationapi and copy the relevant parts of location_locationapi to it
2) replace the default value definitions (mostly just $obj) like so (for e.g. postal code)
3) the definition of location_alter is
I'm not exactly sure how the data is being handled so step 2 might need some tinkering but I'm not there yet.
Comment #7
alexevasion commentedHow is this solution working? If well, do you think you could share it in the form of a patch or a new module?
Comment #8
futuresoon commentedThis is what I got working for me
Comment #9
alexevasion commentedThanks for taking the time to post this! I installed the module, but it didn't have the desired effect. I am wondering how you implement it on your site. I have removed locative information from the content type I am working with by setting the maximum submissions to 0, but the default user location did not appear on newly created nodes of that type. I tried allowing location submissions again (just to see), but it displayed the location I manually set. In essence, I don't understand how the module assigns the user location to their nodes. Am I missing something crucial here? Thanks again, ALEX
Comment #10
yrre7 commentedcan this work for version 5?
Comment #11
yesct commentedtagging.
Comment #12
futuresoon commentedstep 1) at admin/build/modules i enabled
-location
-location node author (this module)
-node locations
-user locations
step 2) at admin/content/node-type/story
i edited a content type so it had maximum of 1 location, 1 location that can be added at once
step 3) at admin/user/settings
basically same as step 2, i set maximum 1 location, 1 location that can be added at once
step 4) in user/1/edit
i set "location name" to "this", "street" to "that", and "additional" to "the other thing" and save
step 5) on node/add/story
the location information for the user appears
I'm not sure if this is the functionality you meant, but this is what this module does.
This worked for me on a copy of Drupal 6.3 (should have done it on the latest, but alas...)
Comment #13
futuresoon commentedhere's my backport of this module to drupal 5 (now with more README.txt! -- the exact same documentation applies to the D6 version above, too)
Comment #14
jnpWebDeveloper-1 commentedGreat that works really well. Thanks for this little module.
Only one thing I noticed that I need to get working. I am using tokens to basically build the content path based on the users's location which makes this little module very helpful for me. Most of the location fields are working fine except for the "_name" ones like "location-province_name". Any chance that we can get this working?
I would also suggest making this into a proper module as I think it might come in handy for quite a few people.
Thanks again
Comment #15
yrre7 commentedIf I use location field in userprofile node type, is it possible to get it default in other content types?
Comment #16
socialnicheguru commentedtaking a look at this and my thought would be to extend the default of the user too using geouser.
I want to use geouser to get the city, region, and country that a user is in
use it to pre-populate $user->location as a default.
That way i am not always asking the user to fill in their location information.
this module looks like it can work with some tweaking.
I was thinking of something along these lines
global $user;
if geouser module is installed then {
if ($user->location['city'] == '') $user->location['city'] = $user->content['geouser']['city'];
if ($user->location['region'] == '') $user->location['region'] = $user->content['geouser']['region'];
if ($user->location['country'] == '') $user->location['country'] = $user->->content['geouser']['country'];
drupal_set_message ('Your location has been set to '. $user->location['city'] .' ,'. $user->location['region'] .' ,'.$user->location['country']);
}
Does this seem like the right start? I could use some real programmers to just help flesh it out.
Thanks,
Chris
Geouser defines this:
$account->content['geouser']['country']
$account->content['geouser']['region']
$account->content['geouser']['city']
Comment #17
socialnicheguru commentedWill this node work with cck location?
Chris
Comment #18
socialnicheguru commentedHow does this module work if there is more than one user location?
Chris
Comment #19
socialnicheguru commentedWill this get its own distribution? or be a subset of the location module and included?
Comment #20
ankur commentedThis is a very specific request that is probably best served by some one-off custom code in a hook_form_alter() implementation.
Comment #21
jfama commentedTwo years later, this saves me. I love you.
Comment #22
rickh commentedHey futuresoon, thanks that works as stated, but is it possible ton inherit LAT/LONG as well? At the moment it inherits everything else but the coordinates. Any help would be greatly appreciated.
Comment #23
Allmighty commentedWould be great if it did pass the lat/long, but i would like to know how to change the default country in the locnodeauthor.
Comment #24
rickharington commentedIs there anyone with the capabilities to get this going for 7.x?