我创建了我自己的模块,名为“cssswitch”。我试图创建自己的HTML布局来显示模块的管理员表单部分。我明白如何使用hook_form_alter()来修改表单元素,但我需要创建整个表单布局来使一些字段彼此相邻。 看来我需要像使用theme_cssswitch_display()显示节点的前端视图一样,但是需要节点的管理部分。从模块的Drupal表格布局
function cssswitch_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
case 'cssswitch_node_form':
$form['hour_start']['#prefix'] = '<div class="start-box">';
$form['ampm_start']['#suffix'] = '</div>';
$form['ampm_start']['#attributes'] = array("style" => "border-width:2px;");
break;
}
}
function cssswitch_theme() {
return array(
'cssswitch_display' => array(
'arguments' => array('node'),
),
);
}
// to display the view of the node
function theme_cssswitch_display($node) {
$output = '<div class="cssswitch-cssfilename">Filename: '.
check_plain($node->cssfilename). '</div>';
$output .= '<div class="cssswitch-time_start">Start: '.
check_plain($node->hour_start). ':'.check_plain($node->minute_start).' '.check_plain($node->ampm_start).'</div>';
$output .= '<div class="cssswitch-time_end">End: '.
check_plain($node->hour_end). ':'.check_plain($node->minute_end).' '.check_plain($node->ampm_end).'</div>';
return $output;
}
感谢您的帮助
谢谢你指点我在正确的方向。我觉得我现在差不多已经有了,但是我的表单并没有以模块中的函数为主题。我在表单函数中添加了主题函数名称,如下所示:$ form ['#theme'] ='cssswitch_form'; 功能cssswitch_theme(){ \t返回阵列( \t 'cssswitch_display'=>数组( \t '参数'=>阵列( '节点'), \t) \t 'cssswitch_form'=>数组( \t 'arguments'=> array(), \t),\t \t); } function theme_cssswitch_form($ form){ $ output =' testing 123'; $ output。= drupal_render($ form); return $ output; } – EricP 2010-05-11 14:29:39
@EricP记得清除缓存,这是主题功能最常见的问题。 – googletorp 2010-05-11 15:12:06