0

drupal_add_jsDrupal 6.只有在创建特定时才执行的正确方法content_type是什么?

我有一些 jQuery 代码只需要执行来控制特定 content_type 创建中的一些表单元素。

我已经有一个模块,它的名称与 content_type 不同。这是一个问题吗?我还能挂在表格上吗?如果是这样,生成特定钩子的正确方法是node/add/content_type什么?

编辑:这仅用于创建,而不是视图。

编辑2:目前不工作的代码:文件:testmod.module

function testmod_form_node_type_form_alter(&$form, &$form_state) {
   if ($form['#node_type']->type == 'testnode') {
     drupal_add_js(drupal_get_path('module', 'testmod') . '/new_msg.js');
   }
}
4

1 回答 1

1

可能有几种方法可以做到,但我会使用form_alter钩子:

function mymodule_form_node_form_alter(&$form, &$form_state) {
  if (!isset($form['#node']->nid) && $form['#node']->type == 'my-type') {
    drupal_add_js('my-file.js');
  }
}
于 2011-11-17T19:10:20.843 回答