0

我想要做的是使用 Drupal 7 和 Location 模块是将节点位置继承或默认为用户位置。原因是我只想让用户编辑一个位置(在他们的个人资料上),并将其显示在该用户创建的所有节点上。任何人都可以帮忙吗?

http://drupal.org/node/1357614

http://drupal.org/node/377600

编辑:

我找到了这个模块,我正试图让纬度和经度工作(就像其他模块一样),但是父案例 '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;

}

}

4

1 回答 1

0

根据您打算如何使用此结果,您甚至可能不需要保存节点的位置。即,如果您想访问视图中的位置数据,您可以使用关系来访问节点作者的位置数据,即使位置数据可能根本没有保存在节点上。但是,这样做意味着视图中的节点将始终与其作者的当前位置相关联,而不是他们在创建节点时设置的位置。

如果您确实想将其保存在节点上,则需要创建一个自定义模块。您可能需要调用hook_form_alter来隐藏节点编辑表单上的 Location 字段,并调用hook_node_presave将用户的 Location 值复制到节点的 Location 值。

于 2012-09-11T15:13:31.823 回答