[英]need some tips on Drupal $form value
I got dpm($form) working. 我让dpm($ form)工作了。 Nice!
真好! This is much better way to view data.
这是查看数据的更好方法。 I am still trying to figure out where stuff is coming from eg: location longitude & latitude.
我仍在尝试找出东西是从哪里来的,例如:位置经度和纬度。 The word 'longitude' is referenced in 20 different places.
“经度”一词在20个不同的地方使用。 I thought this was a likely place to isolate text box for this input field.
我认为这是一个可能隔离此输入字段文本框的地方。 dpm($form['#field_info']['field_store_latitude']['location_settings']['form']['fields']);
dpm($ form ['#field_info'] ['field_store_latitude'] ['location_settings'] ['form'] ['fields']);
Any tips on how to track down individual input elements? 关于如何追踪单个输入元素的任何提示?
** this is not an answer, but a supplement to my first question ** **这不是答案,而是对我的第一个问题的补充**
hi googletorp - 嗨googletorp-
I am trying to modify existing forms using hook_form_alter. 我正在尝试使用hook_form_alter修改现有表单。
After several hours of poking around, I can now turn off location (longitude/latitude) section of a form like this: 经过几个小时的浏览之后,我现在可以关闭表单的位置(经度/纬度)部分,如下所示:
unset($form['field_store_latitude']); 取消设置($ form ['field_store_latitude']);
However, turning off just the latitude like this, does not work: 但是,仅关闭像这样的纬度是行不通的:
unset($form['field_store_latitude']['0']['#location_settings']['form']['fields']['locpick']); unset($ form ['field_store_latitude'] ['0'] ['#location_settings'] ['form'] ['fields'] ['locpick']);
I cannot find a easy way to link id and names in html source with arrays produced by Krumo. 我找不到一种简单的方法来将html源中的ID和名称与Krumo生成的数组链接起来。 In this case id is called "edit-field-store-latitude-0-locpick-user-latitude".
在这种情况下,id称为“ edit-field-store-latitude-0-locpick-user-latitude”。
I need a recipe or guidelines for identifying form elemets in Drupal form. 我需要一个配方或准则来识别Drupal形式的形式要素。
I think I nailed down a solution 我想我确定了解决方案
<?php
// allows you to alter locations fields, which are tricky to access.
// this will require a patch in location module described here:
// http://drupal.org/node/381458#comment-1287362
/**
* Implementation of custom _element_alert() hook.
*/
function form_overrides_location_element_alter(&$element){
// change some location descriptions
$element['locpick']['user_latitude']['#description'] = ' ' . t('Use decimal notation.');
$element['locpick']['user_longitude']['#description'] = ' ' . t('See <a href=!url target=_blank>our help page</a> for more information.', array('!url' => url('latlon_help')));
// or make them disappear entirely
unset($element['locpick']['user_longitude']);
unset($element['locpick']['user_latitude']);
}
/**
* Implementation of form_alter hook.
*/
function form_overrides_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_profile_form':
// change titles in user profile form
$form['account']['name']['#title'] = t('Login Name');
$form['account']['mail']['#title'] = t('Email');
break;
case 'retailer_node_form':
// let's check what is supposed to be here...
print '<pre>';
//print_r($form);
dsm($form);
print '</pre>';
// this works to remove the city
unset($form['field_myvar_latitude']['0']['#location_settings']['form']['fields']['city']);
// let's try #after_build property
$form['#after_build'][]='mymodule_after_build_mynode';
break;
}
}
function mymodule_after_build_mynode($form, $form_values) {
// This will not work for locations fields
return $form;
}`enter code here`
So there is sneaky way to alter the location field, what you need to do is to use the #after_built
callback: 因此,有一个偷偷摸摸的方法来更改位置字段,您需要做的是使用
#after_built
回调:
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'x_node_form') {
// alter the location field
if (isset($form['locations'])) {
$form['locations']['#after_build'][] = 'mymodule_alter_location_field';
}
}
}
/**
* Remove the delete checkbox from location element.
*/
function mymodule_alter_location_field($form_element, &$form_state) {
$location = $form_element[0]; // The location field which you can alter
return $form_element;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.