Hi guys, I've been trying for a while now to get the node latitude and longitude to inherit from the user location. I have been able to adapt a module found which I have embedded below and this works perfectly for everything except the latitude and longitude. The locpick aspect of the field is getting me down. I'm still new to coding and if someone can guide me in the right direction it would be extremely helpful. The module so far
<?php
function location_alter($argument){
$location_alter = array();
global $user;
$uid = $user->uid;
$location_alter = user_load($uid);
$location_alter = $location_alter->location;
return $location_alter[$argument];
}
/**
* Implementation of hook_locationapi().
*/
function locnodeauthor_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
switch ($op) {
case 'field_expand':
switch ($a3) {
case 'name':
return array(
'#type' => 'textfield',
'#title' => t('Location name'),
'#default_value' => $obj != '' ? $obj : location_alter('name'),
'#size' => 64,
'#maxlength' => 64,
'#description' => t('e.g. a place of business, venue, meeting point'),
'#attributes' => NULL,
'#required' => ($a4 == 2),
);
case 'street':
return array(
'#type' => 'textfield',
'#title' => t('Street'),
'#default_value' => $obj != '' ? $obj : location_alter('street'),
'#size' => 64,
'#maxlength' => 64,
'#required' => ($a4 == 2),
);
// Additional is linked to street.
case 'additional':
return array(
'#type' => 'textfield',
'#title' => t('Additional'),
'#default_value' => $obj != '' ? $obj : location_alter('additional'),
'#size' => 64,
'#maxlength' => 64,
// Required is forced OFF because this is technically part of street.
);
case 'city':
return array(
'#type' => 'textfield',
'#title' => t('City'),
'#default_value' => $obj != '' ? $obj : location_alter('city'),
'#size' => 64,
'#maxlength' => 64,
'#description' => NULL,
'#attributes' => NULL,
'#required' => ($a4 == 2),
);
case 'province':
drupal_add_js(drupal_get_path('module', 'location') .'/location_autocomplete.js');
$country = $a5['country'] ? $a5['country'] : variable_get('location_default_country', 'us');
return array(
'#type' => 'textfield',
'#title' => t('State/Province'),
'#autocomplete_path' => 'location/autocomplete/'. $country,
'#default_value' => $obj != '' ? $obj : location_alter('province'),
'#size' => 64,
'#maxlength' => 64,
'#description' => NULL,
// Used by province autocompletion js.
'#attributes' => array('class' => array('location_auto_province')),
'#required' => ($a4 == 2),
);
case 'country':
// Force default.
if ($a4 == 4) {
return array(
'#type' => 'value',
'#value' => variable_get('location_default_country', 'us'),
);
}
else {
$options = array_merge(array('' => t('Please select'), 'xx' => 'NOT LISTED'), location_get_iso3166_list());
return array(
'#type' => 'select',
'#title' => t('Country'),
'#default_value' => $obj,
'#options' => $options,
'#description' => NULL,
'#required' => ($a4 == 2),
// Used by province autocompletion js.
'#attributes' => array('class' => array('location_auto_country')),
);
}
break;
case 'postal_code':
return array(
'#type' => 'textfield',
'#title' => t('Postal code'),
'#default_value' => $obj != '' ? $obj : location_alter('postal_code'),//$location_alter['postal_code'],//location_alter('postal_code'),
'#size' => 16,
'#maxlength' => 16,
'#required' => ($a4 == 2),
);
}
break;
case 'isunchanged':
switch ($a3) {
case 'lid':
// Consider 0, NULL, and FALSE to be equivilent.
if (empty($obj[$a3]) && empty($a4)) {
return TRUE;
}
break;
case 'country':
// Consider ' ' and '' to be equivilent, due to us storing country
// as char(2) in the database.
if (trim($obj[$a3]) == trim($a4)) {
return TRUE;
}
break;
case 'province_name':
case 'country_name':
case 'map_link':
case 'coords':
// Always considered unchanged.
return TRUE;
}
break;
}
}
Comments
Comment #1
legolasboClosing support tickets that have been inactive for over a year to clean up the issue queue. Please reopen if this is still an issue.