ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHP-从模块的Drupal中的表单布局

2019-12-10 03:42:58  阅读:239  来源: 互联网

标签:drupal drupal-fapi drupal-alter php


我创建了自己的名为“ cssswitch”的模块.我正在尝试创建自己的HTML布局以显示模块的管理表单部分.我了解如何使用hook_form_alter()修改表单元素,但是我需要创建整个表单布局,以使某些字段彼此相邻显示.
似乎我需要类似的方法,使主题的前端视图与theme_cssswitch_display()一起显示,但是对于节点的admin部分.

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',
      ),

      );

}

我创建了文件theme / 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); ?>

标签:drupal,drupal-fapi,drupal-alter,php
来源: https://codeday.me/bug/20191210/2098996.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有