我在灯箱中打印“节点/添加”表单时遇到了一些麻烦。
我的custom.module
hook_menu
就像这样:
$items['get-form/%'] = array(
'title' => t('Get a form'),
'description' => t('Get form'),
'page callback' => '_get_form',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
...其中%是id,如“story_node_form”。
然后,我有这样的回调函数:
function _get_form($form_id){
module_load_include('inc', 'node', 'node.pages');
if (strpos($form_string, "_node_form")){
//Test if the form is a <type>_node_form. Is the node/add/<type>
$content_type = explode("_node_form", $form_id)[0];
print drupal_render(node_add($content_type));
}
表格显示在灯箱中。问题是表单的javascript(wysiwyg,节点引用,术语引用,......)不起作用。
我尝试执行Drupal.attachBehaviors()
,Drupal.attachBehaviors(document)
和Drupal.attachBehaviors("#story-node-form")
,但似乎没有任何效果。
任何人都可以提供帮助吗?
答案 0 :(得分:2)
这段代码可以解决问题:
function _get_form($form_id){
global $user;
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => 'ENTER NODE TYPE HERE',
'language' => LANGUAGE_NONE
);
$form_state['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
echo drupal_render(drupal_build_form($form_id, $form_state));
}
您需要获取节点类型以及form_id以使其正常工作,但这应该不会很困难。