[英]Drupal hook alter doens't work
我在這里使用google geocoder:
(function ($) {
Drupal.behaviors.ems_offices = {
attach: function (context, settings) {
geocoder = new google.maps.Geocoder();
$("#edit-submit").click(function(e){
var googleMapAdress = $("#edit-field-offices-google-maps-info-und-0-value").val();
var googleMapsHiddenInput = $("input[name='google_maps_geolocation']");
e.preventDefault();
geocoder.geocode( { 'address': googleMapAdress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (googleMapAdress === '') {
googleMapsHiddenInput.val('');
} else {
googleMapsHiddenInput.val(JSON.stringify(results));
}
}
});
$("#offices-node-form").submit();
});
}
};
}(jQuery));
並嘗試將它們鈎在* .module中
function ems_offices_form_offices_node_form_alter(&$form, &$form_state, $form_id) {
if ('offices_node_form' == $form_id) {
$form['#attached']['js'][] = drupal_get_path("module", "ems_offices")."/assets/js/change_address_to_google_map_object.js" ;
$form['#submit'][] = 'ems_offices_submit';
$form['google_maps_geolocation'] = array(
'#type' => 'hidden',
'#default_value' => '',
);
}
}
function ems_offices_submit(&$form, &$form_state) {
if ($_POST['google_maps_geolocation'] !== '') {
$googleMapsInformation = $_POST['google_maps_geolocation'];
$form_state['values']['field_offices_google_maps_info']['und'][0]['value'] = $googleMapsInformation;
}
}
調試后,我發現js腳本正在運行,並且我有json響應。 但是模塊沒有收到該值。 這個構建可以在我的域上運行但在本地不起作用的有趣部分。 問題出在哪里?
嘗試使用https://www.drupal.org/project/geocoder代替JS非常簡單,而且效果很好!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.