Drupal 模块功能主题化与 ahah

发布于 2024-10-01 01:28:36 字数 2219 浏览 6 评论 0原文

我的主要问题是:

每当通过 ahah (ahah_helper) 重建表单时,是否会调用 theme_hook() 函数?

我试图显示一个选择框,其中包含一些过滤选项,当用户更改它时,它下面的表格也会更改。

我现在已经有了这个:

function veiculos_listar_form($form_state)
{
    $form = array();
    ahah_helper_register($form, $form_state);

    //biulds $options

    $form['listar_veics'] = array(
        '#type'   => 'fieldset',
        '#prefix' => '<div id="listar-veics-wrapper">', 
        '#suffix' => '</div>',
        '#tree'   => TRUE,
        );


    if (!isset($form_state['values']['listar_veics']['filial']))
        $form['#filial_veic'] = 1;
    else 
        $form['#filial_veic'] = $form_state['values']['listar_veics']['filial'];

    $form['listar_veics']['filial'] = array(
        '#type' => 'select', 
        '#title' => "Listar veículos da filial", 
        '#options' => $filiais,
        '#default_value' => $form['#filial_veic'],
        '#ahah' => array(
            'event'     => 'change',
            'path'      => ahah_helper_path(array('listar_veics')),
            'wrapper'   => 'listar-veics-wrapper',
            'method'    => 'replace',
            ),
    );


    return $form;
} 

function veiculos_listar_form_submit($form, &$form_state)
{

}


function _listar_veiculos_tabela($filial)
{
    //builds $header and $data

    $table = theme_table($header, $data);
    return $table;
}


function theme_veiculos_listar_form($form) 
{
    $output = drupal_render($form);
    $filial = $form['#filial_veic'];
    $output .= '<br>' . $filial . '<br>';
    $output .= _listar_veiculos_tabela($filial);
    return $output;
}

function veiculos_theme() {
    return array(
        'veiculos_listar_form' => array(
            'arguments' => array('form' => NULL),),
    );
}

在我的小而无辜的世界中,如果在每个 ahah 事件(更改)上调用 theme_hook ,它应该可以工作。

问题是,打印的变量总是相同的,就像用户选择的变量没有被存储一样。如果用户选择不同的选项,它会显示新选项,但主题打印时 $filial 变量始终相同。

像这样:

http://img230.imageshack.us/img230/9646/62144334.jpg

关于我可以做些什么来完成这项工作有什么建议吗?我正在开发我们自己的模块,因此使用视图模块不是一个好主意。

谢谢。

My main question is:

Does the theme_hook() function gets called whenever the form gets rebuilt via ahah (ahah_helper) ?

I'm trying to show a select box, with some filtering options, when the user changes it, the table below it changes too.

I have this by now:

function veiculos_listar_form($form_state)
{
    $form = array();
    ahah_helper_register($form, $form_state);

    //biulds $options

    $form['listar_veics'] = array(
        '#type'   => 'fieldset',
        '#prefix' => '<div id="listar-veics-wrapper">', 
        '#suffix' => '</div>',
        '#tree'   => TRUE,
        );


    if (!isset($form_state['values']['listar_veics']['filial']))
        $form['#filial_veic'] = 1;
    else 
        $form['#filial_veic'] = $form_state['values']['listar_veics']['filial'];

    $form['listar_veics']['filial'] = array(
        '#type' => 'select', 
        '#title' => "Listar veículos da filial", 
        '#options' => $filiais,
        '#default_value' => $form['#filial_veic'],
        '#ahah' => array(
            'event'     => 'change',
            'path'      => ahah_helper_path(array('listar_veics')),
            'wrapper'   => 'listar-veics-wrapper',
            'method'    => 'replace',
            ),
    );


    return $form;
} 

function veiculos_listar_form_submit($form, &$form_state)
{

}


function _listar_veiculos_tabela($filial)
{
    //builds $header and $data

    $table = theme_table($header, $data);
    return $table;
}


function theme_veiculos_listar_form($form) 
{
    $output = drupal_render($form);
    $filial = $form['#filial_veic'];
    $output .= '<br>' . $filial . '<br>';
    $output .= _listar_veiculos_tabela($filial);
    return $output;
}

function veiculos_theme() {
    return array(
        'veiculos_listar_form' => array(
            'arguments' => array('form' => NULL),),
    );
}

In my little and innocent world, it should work if theme_hook is called on every ahah event (change).

The problem is, the variable printed is always the same, like what the user is choosing isn't being stored. If the user select a different options, it shows the new option, but the $filial variable is always the same when the theme prints.

Like this:

http://img230.imageshack.us/img230/9646/62144334.jpg

Any suggestion on what i could do to make this work? I'm developing our own module, so using views module isn't a good idea.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-10-08 01:28:37

你应该这样重做代码。
啊哈回调我没有写,我想你不会有问题。
在 drupal.org 上查看一些示例

function veiculos_listar_form($form_state)
{
    $form = array();
    ahah_helper_register($form, $form_state);

    //biulds $options

 // remove divs because we do not want to reload selector with ahah
    $form['listar_veics'] = array(
        '#type'   => 'fieldset',
        '#tree'   => TRUE,
    );


    if (!isset($form_state['values']['listar_veics']['filial']))
        $form['#filial_veic'] = 1;
    else 
        $form['#filial_veic'] = $form_state['values']['listar_veics']['filial'];

  // add cover div here, because we will reload table
    $form['table'] = array(
        '#prefix' => '<div id="listar-veics-wrapper">', 
        '#suffix' => '</div>',
        '#type' => 'markup',
        '#value' => _listar_veiculos_tabela($form['#filial_veic']),
    );

    $form['listar_veics']['filial'] = array(
        '#type' => 'select', 
        '#title' => "Listar veículos da filial", 
        '#options' => $filiais,
        '#default_value' => $form['#filial_veic'],
        '#ahah' => array(
            'event'     => 'change',
            'path'      => ahah_helper_path(array('listar_veics')),
            'wrapper'   => 'listar-veics-wrapper',
            'method'    => 'replace',
            ),
    );


    return $form;
} 

function veiculos_listar_form_submit($form, &$form_state)
{

}


function _listar_veiculos_tabela($filial)
{
    //builds $header and $data

    $table = theme_table($header, $data);
    return $table;
}


function theme_veiculos_listar_form($form) 
{
    $output = drupal_render($form);
    return $output;
}

function veiculos_theme() {
    return array(
        'veiculos_listar_form' => array(
            'arguments' => array('form' => NULL),),
    );
}

You should redo code this way.
Ahah callback I do not wrote, I think you would not have problem with it.
Check some examples on drupal.org

function veiculos_listar_form($form_state)
{
    $form = array();
    ahah_helper_register($form, $form_state);

    //biulds $options

 // remove divs because we do not want to reload selector with ahah
    $form['listar_veics'] = array(
        '#type'   => 'fieldset',
        '#tree'   => TRUE,
    );


    if (!isset($form_state['values']['listar_veics']['filial']))
        $form['#filial_veic'] = 1;
    else 
        $form['#filial_veic'] = $form_state['values']['listar_veics']['filial'];

  // add cover div here, because we will reload table
    $form['table'] = array(
        '#prefix' => '<div id="listar-veics-wrapper">', 
        '#suffix' => '</div>',
        '#type' => 'markup',
        '#value' => _listar_veiculos_tabela($form['#filial_veic']),
    );

    $form['listar_veics']['filial'] = array(
        '#type' => 'select', 
        '#title' => "Listar veículos da filial", 
        '#options' => $filiais,
        '#default_value' => $form['#filial_veic'],
        '#ahah' => array(
            'event'     => 'change',
            'path'      => ahah_helper_path(array('listar_veics')),
            'wrapper'   => 'listar-veics-wrapper',
            'method'    => 'replace',
            ),
    );


    return $form;
} 

function veiculos_listar_form_submit($form, &$form_state)
{

}


function _listar_veiculos_tabela($filial)
{
    //builds $header and $data

    $table = theme_table($header, $data);
    return $table;
}


function theme_veiculos_listar_form($form) 
{
    $output = drupal_render($form);
    return $output;
}

function veiculos_theme() {
    return array(
        'veiculos_listar_form' => array(
            'arguments' => array('form' => NULL),),
    );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文