【问题标题】:drupal 7 form theme function not being called未调用drupal 7表单主题功能
【发布时间】:2013-04-11 16:39:03
【问题描述】:

我正在尝试为自定义模块中的简单表单注册主题函数,但未调用主题函数。我只是得到了基本的形式。

这是我的 hook_theme():

function kss_membership_theme($existing, $type, $theme, $path){
    $items = array();
    $items['kss_membership_payment_form'] = array(
        'render element' => 'form',
    );
    return $items;
}

对于这种形式:

/**
 * Returns the form for the second page of the payment process
 */
function kss_membership_payment_form($form, &$form_state) {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('We currently accept Paypal payments'),
  );

    $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => array('kss_membership_payment_form_submit'),
  );

  $form['#theme'] = array('theme_kss_membership_payment_form');
  return $form;
}

这里是主题功能:

function theme_kss_membership_payment_form($variables) {
    // Isolate the form definition form the $variables array
    $form = $variables['form'];

    $output = '<h2>' . t('Please enter your information below') . '</h2>';
            $output .= '<div id="personal_details">';

    $output .= drupal_render($form['description']);
    $output .= drupal_render($form['submit']);
    // Additional template output goes here....
    $output .= '</div>';

    $output .= drupal_render_children($form);
    return $output;
}

【问题讨论】:

    标签: drupal-7 drupal-theming drupal-fapi hook-theme


    【解决方案1】:

    你非常接近解决方案,只有一个问题存在。

    主题调用错误

    $form['#theme'] = array('theme_kss_membership_payment_form');

    你需要打电话

    $form['#theme'] = array('kss_membership_payment_form');

    之后,您必须从管理员 => 配置 => 性能 => 清除缓存按钮中清除缓存。

    /**
     * Returns the form for the second page of the payment process
     */
    function kss_membership_payment_form($form, &$form_state) {
      $form['description'] = array(
        '#type' => 'item',
        '#title' => t('We currently accept Paypal payments'),
      );
    
        $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
        '#submit' => array('kss_membership_payment_form_submit'),
      );
    
      $form['#theme'] = array('kss_membership_payment_form');
      return $form;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      相关资源
      最近更新 更多