在Drupal 7中为表单调用自定义Theme()函数

Sté*_*e V 3 hook themes drupal

Drupal不会在我的模块中为我的表单调用我的主题函数.

我在.module文件中添加了hook_theme,如下所示:

function agil_theme() {
    return array(
        'agil_list_form' => array(
            'render element' => 'form',
        ),
    );
}
Run Code Online (Sandbox Code Playgroud)

其中:

  • agil是我模块的名称(不是我的主题)
  • agil_list_form是我的表单声明的名称(使用默认主题的chich呈现)

我想调用一个函数来创建我自己的标记,如下所示:

function theme_agil_list_form($form) {
  $output  = "<table><th><td></td><td>".t('Title')."</td><td>".t('Link')."</td></th>";
    $output .= "<tr><td>";
  $output .= drupal_render($form['name']);
  ...
Run Code Online (Sandbox Code Playgroud)

但是Drupal从来没有调用过这个函数......我清除了缓存但没有...

我在哪里想念什么?

我还读到了关于Drupal 7中新主题声明的内容:http: //drupal.org/update/modules/6/7#hook_theme_render_changes

Cli*_*ive 5

Drupal 7中的所有主题函数都采用单个数组参数(通常命名为$vars$variables按约定),该数组包含您声明的变量/ render元素.主题函数本身看起来像这样:

function theme_agil_list_form($vars) {
  $form = $vars['form'];
  // Now manipulate $form
}
Run Code Online (Sandbox Code Playgroud)

此外,您需要告诉Drupal您的表单将使用此主题,方法是在表单函数中执行此操作:

$form['#theme'] = 'agil_list_form';
Run Code Online (Sandbox Code Playgroud)