【问题标题】:Drupal 6: theme a category in hook_user()Drupal 6:主题 hook_user() 中的类别
【发布时间】:2011-07-19 13:38:04
【问题描述】:

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

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

问候 琼瑶浆

【问题讨论】:

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


    【解决方案1】:
    // 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;
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 查看不是这里的问题。我想编辑我的表格。所以“视图”操作不会被调用。我有点想念那个;)
      猜你喜欢
      • 1970-01-01
      • 2011-07-16
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多