0
votes

I've got a problem with Drupal 6 and the hook_user(). I have created a module, that adds new categories to the user node. One of them is "addresses". I have this new category and I can access it via "My Account". Now when the op "form" is called, i collect all adresses, that I need. But I can't find a way to theme them. Right now, I have several fields just dumped to the page instead of being nicely arranged in tables. I'm aware of the "user-profile.tpl.php", but I can't alter that, because there may be other modules, that alter that one too.

Does anyone have an idea, of how to achieve a nicely themed table in an user category?

Regards Gewürzwiesel

2

2 Answers

2
votes
// 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;
}
0
votes

Use Drupal 6's hook_user 'view' operation. From the docs: "view": The user's account information is being displayed. The module should format its custom additions for display, and add them to the $account->content array.