我无法让 drupal_get_form 传递节点数据。代码片段如下。drupal_get_form 文档 (api.drupal.org) 声明它将传递额外的参数。我基于未传递节点数据,因为(显然)$node['language'] 未在 hook_form 中定义,导致 $form['qqq'] 未创建,因此显示预览按钮。
我的目标是使用路径“node/add/author”显示预览按钮,但不显示“milan/author/add”。实现这一目标的任何替代方法都会有所帮助,但我想回答的问题在前一段中。我读过的所有内容都表明它应该可以工作。
这个菜单项
$items['milan/author/add'] = array(
'title' => '添加作者',
'页面回调' => 'get_author_form',
'访问参数' => 数组('访问内容'),
'文件' => 'author.pages.inc',
);
调用此代码
函数 get_author_form() {
//返回node_form(NULL,NULL);
//return drupal_get_form('author_form');
返回 author_ajax_form('author');
}
功能 author_ajax_form($type) {
全局$用户;
module_load_include('inc', 'node', 'node.pages');
$types = node_get_types();
$type = isset($type) ?str_replace('-', '_', $type) : NULL;
// 如果已指定节点类型,则验证其存在。
if (isset($types[$type]) && node_access('create', $type)) {
// 初始化设置:
$node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, '语言' => 'bbb','bbb' => 'TRUE');
$output = drupal_get_form($type .'_node_form', $node);
}
返回$输出;
}
这是 hook_form 和 hook_form_alter 代码
功能 author_form_author_node_form_alter(&$form, &$form_state) {
$form['作者']=NULL;
$form['taxonomy']=NULL;
$form['options']=NULL;
$form['菜单']=NULL;
$form['comment_settings']=NULL;
$form['files']=NULL;
$form['revision_information']=NULL;
$form['附件']=NULL;
if($form["qqq"]) {
$form['buttons']['preview']=NULL;
}
}
功能作者表格(&$节点){
返回 make_author_form(&$node);
}
函数 make_author_form(&$node) {
全局$用户;
$type = node_get_types('type', $node);
$node = author_make_title($node);
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t($node->title), 'node/' . $node->nid)));
$form['authorset'] = 数组(
'#type' => '字段集',
'#title' => t('作者'),
'#weight' => -50,
'#collapsible' => 错误,
'#collapsed' => 错误,
);
$form['author_id'] = 数组(
'#access' => user_access('创建 pd_recluse 条目'),
'#type' => '隐藏',
'#default_value' => $node->author_id,
'#weight' => -20
);
$form['authorset']['last_name'] = array(
'#type' => '文本域',
'#title' => t('姓氏'),
'#maxlength' => 60,
'#default_value' => $node->last_name
);
$form['authorset']['first_name'] = array(
'#type' => '文本域',
'#title' => t('名字'),
'#maxlength' => 60,
'#default_value' => $node->first_name
);
$form['authorset']['middle_name'] = array(
'#type' => '文本域',
'#title' => t('中间名'),
'#maxlength' => 60,
'#default_value' => $node->middle_name
);
$form['authorset']['suffix_name'] = array(
'#type' => '文本域',
'#title' => t('后缀名'),
'#maxlength' => 14,
'#default_value' => $node->suffix_name
);
$form['authorset']['body_filter']['body'] = array(
'#access' => user_access('创建 pd_recluse 条目'),
'#type' => 'textarea',
'#title' => '描述作者',
'#default_value' => $node->body,
'#required' => 错误,
'#weight' => -19
);
$form['状态'] = 数组(
'#type' => '隐藏',
'#default_value' => '1'
);
$form['promote'] = 数组(
'#type' => '隐藏',
'#default_value' => '1'
);
$form['name'] = 数组(
'#type' => '隐藏',
'#default_value' => $user->name
);
$form['格式'] = 数组(
'#type' => '隐藏',
'#default_value' => '1'
);
// 注意在 node_example 中,这里有一些附加代码对于这个简单的节点类型是不需要的
$thepath='米兰/作者';
if($_REQUEST["theletter"]) {
$thepath .= "/" 。$_REQUEST["这封信"];
}
如果($节点['语言']){
$thepath='米兰/authorajaxclose';
$form['qqq'] = 数组(
'#type' => '隐藏',
'#default_value' => '1'
);
}
$form['#redirect'] = $thepath;
返回$表格;
}
该菜单路径与此主题一致(PHPTemplate)