0

我正在尝试了解 PHP 数组和 drupal,并使用函数 system_modules(在 modules/system/system.admin.inc)作为指导,看看我是否可以重新创建和理解 drupal 在表格中打印表单的方式。我已经在主题功能中指出了我的问题,但我不明白一些问题,想知道是否有人可以在正确的方向上帮助我。

目标是打印 2 个字段集,每个字段集有两行(如数组中定义的那样)。我现在能够生成带有标题但没有任何行的字段集。我认为这与 drupal_render 有关,但是当我尝试修改结果不正确时。此外,如果我从数组键中排除主题标签 (#),我不明白为什么代码会崩溃。这是什么原因,PHP 数组不需要标签。

示例代码:

function sb_erp_test($form, $form_state){
$form['Headers'] = array('#tree' => TRUE);


$form['Headers']=  array(
    '#tree' => TRUE,
);
$form['Headers']['a']=  array(
    array('#subset1' => 'Group a Line 1 Field 1',
        '#subset2' => 'Group a Line 1 Field 2',
        '#Group' => 'Group a Line 1 Field 3',
        '#ID' => 'Group a Line 1 Field 4',
    ),
    array('#subset1' => 'Group a Line 2 Field 1',
        '#subset2' => 'Group a Line 2 Field 2',
        '#Group' => 'Group a Line 2 Field 3',
        '#ID' => 'Group a Line 2 Field 4',
    ),      
);
$form['Headers']['b']=  array(
    array('#subset1' => 'Group b Line 1 Field 1',
        '#subset2' => 'Group b Line 1 Field 2',
        '#Group' => 'Group b Line 1 Field 3',
        '#ID' => 'Group b Line 1 Field 4',
    ),
    array('#subset1' => 'Group b Line 2 Field 1',
        '#subset2' => 'Group b Line 2 Field 2',
        '#Group' => 'Group b Line 2 Field 3',
        '#ID' => 'Group b Line 2 Field 4',
    ),      
);
foreach(element_children($form['Headers']) as $tmp){


    //drupal_set_message($tmp);
    $form['Headers'][$tmp] += array(
        '#type' => 'fieldset',
        '#title' => t($tmp),
        '#collapsible' => TRUE,
        //'The theme reference generates the rows.
        '#theme' => 'test_fieldset',
        '#header' => array(
            //array('data' => t('Enabled'), 'class' => array('checkbox')),
            t('ID'),
            t('subset1'),
            t('subset2'),
            //array('data' => t('Operations'), 'colspan' => 3),
        ),
    );


}
return $form;
}


function theme_test_fieldset($variables){
    $form = $variables['form'];
    // Individual table headers.
    $rows = array();
    // Iterate through all the modules, which are
    // children of this fieldset.

    foreach(element_children($form) as $key){
        // Stick it into $module for easier accessing.
        $module = $form[$key];
        //$row = array();
        //$row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));
        $row[] = '<label><strong>' . drupal_render($module['#ID']) . '</strong></label>';
        // $row[] = drupal_render($module['version']);
        // Add the description, along with any modules it requires.

        $description = drupal_render($module['#subset1']);
        $description3 = drupal_render($module['#subset2']);

        $row[] = array('data' => $description, 'class' => array('description'));
        $row[] = array('data' => $description3, 'class' => array('description'));
        // Display links (such as help or permissions) in their own columns.
        $rows[] = $row;
    }

    return theme('table', array('header' => $form['#header'], 'rows' => $rows));


}
4

0 回答 0