Drupal 7 - 将字段描述放在字段上方
默认情况下,在 Drupal 7 中,字段描述显示在字段下方。有什么办法可以将它们移到场地上方吗?
在 Drupal 6 中,您可以将以下代码粘贴到 template.php 中以移动描述。然而,该代码在 Drupal 7 中不起作用:
/**
* Place CCK Options above field .
*/
function ThemeNAME_form_element($element, $value) {
$output = ' <div class="form-item"';
if(!empty($element['#id'])) {
$output .= ' id="'. $element['#id'] .'-wrapper"';
}
$output .= ">\n";
$required = !empty($element['#required']) ? '<span class="form-required" title="'.t('This field is required.').'">*</span>' : '';
if (!empty($element['#title'])) {
$title = $element['#title'];
if (!empty($element['#id'])) {
$output .= ' <label for="'. $element['#id'] .'">'. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label> \n";
}
else {
$output .= ' <label>'. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
}
}
if (!empty($element['#description'])) {
$output .= ' <div class="description">' . $element['#description'] ."</div> \n";
}
$output .= " $value\n";
$output .= " </div> \n";
return $output;
}
By default in Drupal 7, field descriptions appear below the field. Is there anyway to move them above the field?
In Drupal 6, you could paste the following code in template.php to move the descriptions. However, the code does not work in Drupal 7:
/**
* Place CCK Options above field .
*/
function ThemeNAME_form_element($element, $value) {
$output = ' <div class="form-item"';
if(!empty($element['#id'])) {
$output .= ' id="'. $element['#id'] .'-wrapper"';
}
$output .= ">\n";
$required = !empty($element['#required']) ? '<span class="form-required" title="'.t('This field is required.').'">*</span>' : '';
if (!empty($element['#title'])) {
$title = $element['#title'];
if (!empty($element['#id'])) {
$output .= ' <label for="'. $element['#id'] .'">'. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label> \n";
}
else {
$output .= ' <label>'. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
}
}
if (!empty($element['#description'])) {
$output .= ' <div class="description">' . $element['#description'] ."</div> \n";
}
$output .= " $value\n";
$output .= " </div> \n";
return $output;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,并通过将其添加到主题的 template.php 文件中来完成此任务。
不要忘记清除缓存!
I had the same problem and accomplished this by adding it to my theme's template.php file.
Don't forget to clear your cache!
https://drupal.org/project/label_help 也应该可以解决问题。希望有帮助
https://drupal.org/project/label_help should also do the trick. Hope that helps
您可以对要更改的特定字段进行主题覆盖,或者对所有字段进行更通用的覆盖。阅读此内容:
http://api. drupal.org/api/drupal/modules--field--field.module/function/theme_field/7
您根本不需要搞乱 template.php 来执行此操作。
You can do a theme override for the specific field you want to change or a more general override for all fields. Read this:
http://api.drupal.org/api/drupal/modules--field--field.module/function/theme_field/7
You shouldn't have to mess with template.php at all to do this.
Rumblewand 的答案,有一个条件可以防止单选按钮/复选框也被扔到输入上方的 div 中。 (可能是更有效的方法。)
Rumblewand's answer, with a conditional that prevents radio/checkboxes from also being thrown into a div above the input. (May be more efficient ways to do this.)