我想要做的是使用 Drupal 7 和 Location 模块是将节点位置继承或默认为用户位置。原因是我只想让用户编辑一个位置(在他们的个人资料上),并将其显示在该用户创建的所有节点上。任何人都可以帮忙吗?
http://drupal.org/node/1357614
编辑:
我找到了这个模块,我正试图让纬度和经度工作(就像其他模块一样),但是父案例 'locpick' 让我很困惑,我就是无法做到这一点。
<?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;
}
}