当创建特定的content_type
时,执行drupal_add_js
的正确方法是什么?
我有一些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');
}
}
可能有几种方法可以做到这一点,但我会使用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');
}
}