Is it possible to do so within the current framework? I'm developing a site to share household goods among neighbors, so this would be the logical setup. Anyone have any experience with such modifications? Thanks!

Comments

alexevasion’s picture

OK, 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.

alexevasion’s picture

Anyone? Any help would be appreciated. Thanks, ALEX

futuresoon’s picture

I'm exploring hook_form_alter for this, but I dunno if it can be done that way yet.

alexevasion’s picture

Please let me know if you have any success!

futuresoon’s picture

Apparently 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.

futuresoon’s picture

Yeah 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)

            '#default_value'  => $obj != '' ? $obj : location_alter('postal_code'),

3) the definition of location_alter is

function location_alter($field){
  $location_alter = array();
  global $user;
  $uid = $user->uid;
  $location_alter = user_load($uid);
  $location_alter = $location_alter->location;
  return $location_alter[$field];
}

I'm not exactly sure how the data is being handled so step 2 might need some tinkering but I'm not there yet.

alexevasion’s picture

How is this solution working? If well, do you think you could share it in the form of a patch or a new module?

futuresoon’s picture

StatusFileSize
new7.05 KB

This is what I got working for me

alexevasion’s picture

Thanks 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

yrre7’s picture

can this work for version 5?

yesct’s picture

futuresoon’s picture

step 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...)

futuresoon’s picture

StatusFileSize
new8.44 KB

here'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)

jnpWebDeveloper-1’s picture

Great 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

yrre7’s picture

If I use location field in userprofile node type, is it possible to get it default in other content types?

socialnicheguru’s picture

taking 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']

socialnicheguru’s picture

Will this node work with cck location?

Chris

socialnicheguru’s picture

How does this module work if there is more than one user location?

Chris

socialnicheguru’s picture

Will this get its own distribution? or be a subset of the location module and included?

ankur’s picture

Status: Active » Closed (fixed)

This is a very specific request that is probably best served by some one-off custom code in a hook_form_alter() implementation.

jfama’s picture

Two years later, this saves me. I love you.

rickh’s picture

Hey 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.

Allmighty’s picture

Would be great if it did pass the lat/long, but i would like to know how to change the default country in the locnodeauthor.

rickharington’s picture

Is there anyone with the capabilities to get this going for 7.x?