gpt4 book ai didi

php - 从模块在 drupal 中形成布局

转载 作者:搜寻专家 更新时间:2023-10-31 20:55:41 24 4
gpt4 key购买 nike

我创建了自己的名为“cssswitch”的模块。我正在尝试创建自己的 html 布局来显示模块的管理表单部分。我了解如何使用 hook_form_alter() 修改表单元素,但我需要创建整个表单布局以使某些字段彼此相邻显示。看来我需要一些类似于使用 theme_cssswitch_display() 显示节点的前端 View 的方式,但对于节点的管理部分。

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

谢谢你的帮助

最佳答案

我现在已经解决了所有问题。我的 hook_theme 是这样的:

function cssswitch_theme() {

return array(
'cssswitch_display' => array(
'arguments' => array('node'),
),

'cssswitch_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'cssswitch-node-form.tpl.php',
),

);

}

我创建了文件 themes/garland/cssswitch-node-form.tpl.php然后我可以控制放置任何表单元素的位置,如下所示:

<style>
#edit-hour-start-wrapper, #edit-minute-start-wrapper, #edit-ampm-start-wrapper, #edit-hour-end-wrapper, #edit-minute-end-wrapper, #edit-ampm-end-wrapper {
float:left;
margin-right:25px;
}
</style>
<div id="regform1">

<?php print drupal_render($form['title']); ?>
<?php print drupal_render($form['cssfilename']); ?>

<fieldset class="group-account-basics collapsible">
<legend>Time Start</legend>
<?php print drupal_render($form['hour_start']); ?>
<?php print drupal_render($form['minute_start']); ?>
<?php print drupal_render($form['ampm_start']); ?>
</fieldset>

<fieldset class="group-account-basics collapsible"><legend>Time end</legend>
<?php print drupal_render($form['hour_end']); ?>
<?php print drupal_render($form['minute_end']); ?>
<?php print drupal_render($form['ampm_end']); ?>
</fieldset>
</div>

<?php print drupal_render($form['options']); ?>
<?php print drupal_render($form['author']); ?>
<?php print drupal_render($form['revision_information']); ?>
<?php print drupal_render($form['path']); ?>
<?php print drupal_render($form['attachments']); ?>
<?php print drupal_render($form['comment_settings']); ?>
<?php print drupal_render($form); ?>

关于php - 从模块在 drupal 中形成布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2805969/

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