gpt4 book ai didi

Drupal 7 - 在字段上方放置字段描述

转载 作者:行者123 更新时间:2023-12-04 21:57:25 25 4
gpt4 key购买 nike

默认情况下,在 Drupal 7 中,字段说明显示在字段下方。有没有办法把它们移到 field 上方?

在 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;
}

最佳答案

我遇到了同样的问题,通过将它添加到我的主题的 template.php 文件中来解决这个问题。

/**
* Replacement for theme_webform_element() to enable descriptions to come BEFORE the field to be filled out.
*/
function danland_webform_element($variables) {
$element = $variables['element'];
$value = $variables['element']['#children'];

$wrapper_classes = array(
'form-item',
);
$output = '<div class="' . implode(' ', $wrapper_classes) . '" id="' . $element['#id'] . '-wrapper">' . "\n";
$required = !empty($element['#required']) ? '<span class="form-required" title="' . t('This field is required.') . '">*</span>' : '';

if (!empty($element['#title'])) {
$title = $element['#title'];
$output .= ' <label for="' . $element['#id'] . '">' . 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 .= '<div id="' . $element['#id'] . '">' . $value . '</div>' . "\n";

$output .= "</div>\n";

return $output;
}

不要忘记清除缓存!

关于Drupal 7 - 在字段上方放置字段描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4979071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com