0

我遇到了 Drupal 6 和 hook_user() 的问题。我创建了一个模块,向用户节点添加新类别。其中之一是“地址”。我有这个新类别,我可以通过“我的帐户”访问它。现在,当调用“表单”操作时,我收集了我需要的所有地址。但我找不到为它们设置主题的方法。现在,我有几个字段只是转储到页面上,而不是在表格中很好地排列。我知道“user-profile.tpl.php”,但我不能改变它,因为可能有其他模块也改变了那个。

有没有人知道如何在用户类别中实现一个很好的主题表?

问候琼瑶浆

4

2 回答 2

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;
}
于 2012-10-25T11:10:34.143 回答
0

使用 Drupal 6 的 hook_user 'view' 操作。来自文档:“视图”:正在显示用户的帐户信息。该模块应格式化其自定义添加以供显示,并将它们添加到 $account->content 数组。

于 2011-07-19T13:47:38.860 回答