is this possible? I have users set their location on their profile page and optionally insert Latitude/longitude via Gmap. Now I would like to have all nodes to automatically have their author's location as default value.
at the moment, all node edit forms are empty as default.
also it would be cool to have the Latitude/Longitude taken over from the user profile, altho this might be a gmap issue...

Comments

sterwa’s picture

A crude hack would involve getting into location.module and adding inside function location_form

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.

sterwa’s picture

i just noticed, this is to prepopulate user location. But prepopulating lon/lat works really the same way, only you would need to alter location_latlon_form function instead.

catch’s picture

Status: Active » Closed (duplicate)