Drupal 6:在hook_user()中设置一个类别

时间:2011-07-19 13:38:04

标签: drupal drupal-6 drupal-theming drupal-hooks

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

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

此致 Gewürzwiesel

2 个答案:

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

答案 1 :(得分:0)

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