2011-07-19 91 views
0

我遇到了Drupal 6和hook_user()的問題。我創建了一個模塊,它爲用戶節點添加了新的類別。其中之一是「地址」。我有這個新的類別,我可以通過「我的帳戶」訪問它。現在,當「表單」被調用時,我收集所有我需要的地址。但我找不到一種主題。現在,我有幾個字段只是傾倒在頁面上,而不是很好地安排在表格中。我知道「user-profile.tpl.php」,但我無法改變這種情況,因爲可能有其他模塊也會改變它。Drupal 6:hook_user()中的主題類別

有沒有人有一個想法,如何在用戶類別中實現一個很好的主題表?

問候 Gewürzwiesel

回答

0

使用Drupal 6的hook_user '視圖' 操作。從文檔:「查看」:正在顯示用戶的帳戶信息。該模塊應該格式化自定義添加項以顯示,並將它們添加到$ account-> content數組中。

+0

查看不是這裏的問題。我想編輯我的表單。所以'視圖'操作不會被調用。 我有點錯過了,說;) –

2
// hook_user 
function mymodule_user($op, &$edit, &$account, $category = NULL) { 
    switch ($op) { 
    case 'categories': 
    $output[] = array(
     'name' => 'new_category', 
     'title' => t('new_category'), 
    ); 
    case 'form': 
    if ($category == 'new_category') { 
     $form_state = array(); 
     $form = mymodule_new_category_form($form_state, $account); 
     return $form; 
    } 
    break; 
    } 
} 

function mymodule_new_category_form(&$form_state, $account) { 
    $form = array(); 

    $form['new_category'] = array(
    '#type' => 'fieldset', 
    '#title' => t('new_category'), 
    '#theme' => 'mymodule_new_category_form', 
); 
    $form['new_category']['text1'] = array(
    '#type' => 'textfield', 
    '#title' => t('text1'), 
); 
    $form['new_category']['text2'] = array(
    '#type' => 'textfield', 
    '#title' => t('text2'), 
); 
    $form['new_category']['text3'] = array(
    '#type' => 'textfield', 
    '#title' => t('text3'), 
); 

    return $form; 
} 

// hook_theme 
function mymodule_theme() { 
    return array(
    'mymodule_new_category_form' => array(
     'arguments' => array('form' => NULL), 
    ), 
); 
} 

function theme_mymodule_new_category_form($form) { 
    $rows = array(); 

    foreach (element_children($form) as $form_field_name) { 
    $description = $form[$form_field_name]['#description']; 
    $form[$form_field_name]['#description'] = ''; 

    $title = theme('form_element', $form[$form_field_name], ''); 
    $form[$form_field_name]['#description'] = $description; 
    $form[$form_field_name]['#title'] = ''; 
    $row = array(
     'data' => array(
     0 => array('data' => $title, 'class' => 'label_cell'), 
     1 => drupal_render($form[$form_field_name]) 
    ) 
    ); 
    $rows[] = $row; 
    } 

    $output = theme('table', array(), $rows); 
    $output .= drupal_render($form); 

    return $output; 
}