我還沒有能夠讓drupal_get_form傳遞節點數據。代碼片段如下。 drupal_get_form文檔(api.drupal.org)聲明它會傳遞額外的參數。因爲(顯然)$ node ['language']未在hook_form中定義,導致$ form ['qqq']不能被創建,因此預覽按鈕顯示出來,所以我沒有傳遞節點數據。drupal_get_form不是沿着節點數組傳遞
這裏我的目標是預覽按鈕顯示使用路徑「節點/添加/作者」,但不顯示「米蘭/作者/添加」。實現這一目標的任何替代方法都會有幫助,但我想回答的問題在前一段中。我讀過的所有內容都表明它應該起作用。
該菜單項
$items['milan/author/add'] = array( 'title' => 'Add Author', 'page callback' => 'get_author_form', 'access arguments' => array('access content'), 'file' => 'author.pages.inc', );
調用此代碼
function get_author_form() { //return node_form(NULL,NULL); //return drupal_get_form('author_form'); return author_ajax_form('author'); } function author_ajax_form($type) { global $user; module_load_include('inc', 'node', 'node.pages'); $types = node_get_types(); $type = isset($type) ? str_replace('-', '_', $type) : NULL; // If a node type has been specified, validate its existence. if (isset($types[$type]) && node_access('create', $type)) { // Initialize settings: $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => 'bbb','bbb' => 'TRUE'); $output = drupal_get_form($type .'_node_form', $node); } return $output; }
這裏是hook_form和hook_form_alter代碼
function author_form_author_node_form_alter(&$form, &$form_state) { $form['author']=NULL; $form['taxonomy']=NULL; $form['options']=NULL; $form['menu']=NULL; $form['comment_settings']=NULL; $form['files']=NULL; $form['revision_information']=NULL; $form['attachments']=NULL; if($form["qqq"]) { $form['buttons']['preview']=NULL; } } function author_form(&$node) { return make_author_form(&$node); } function make_author_form(&$node) { global $user; $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'] = array( '#type' => 'fieldset', '#title' => t('Author'), '#weight' => -50, '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['author_id'] = array( '#access' => user_access('create pd_recluse entries'), '#type' => 'hidden', '#default_value' => $node->author_id, '#weight' => -20 ); $form['authorset']['last_name'] = array( '#type' => 'textfield', '#title' => t('Last Name'), '#maxlength' => 60, '#default_value' => $node->last_name ); $form['authorset']['first_name'] = array( '#type' => 'textfield', '#title' => t('First Name'), '#maxlength' => 60, '#default_value' => $node->first_name ); $form['authorset']['middle_name'] = array( '#type' => 'textfield', '#title' => t('Middle Name'), '#maxlength' => 60, '#default_value' => $node->middle_name ); $form['authorset']['suffix_name'] = array( '#type' => 'textfield', '#title' => t('Suffix Name'), '#maxlength' => 14, '#default_value' => $node->suffix_name ); $form['authorset']['body_filter']['body'] = array( '#access' => user_access('create pd_recluse entries'), '#type' => 'textarea', '#title' => 'Describe Author', '#default_value' => $node->body, '#required' => FALSE, '#weight' => -19 ); $form['status'] = array( '#type' => 'hidden', '#default_value' => '1' ); $form['promote'] = array( '#type' => 'hidden', '#default_value' => '1' ); $form['name'] = array( '#type' => 'hidden', '#default_value' => $user->name ); $form['format'] = array( '#type' => 'hidden', '#default_value' => '1' ); // NOTE in node_example there is some addition code here not needed for this simple node-type $thepath='milan/author'; if($_REQUEST["theletter"]) { $thepath .= "/" . $_REQUEST["theletter"]; } if($node['language']) { $thepath='milan/authorajaxclose'; $form['qqq'] = array( '#type' => 'hidden', '#default_value' => '1' ); } $form['#redirect'] = $thepath; return $form; }
該菜單路徑與此主題(PHPTemplate)一致
這不是一個壞主意,但不是問題。這是通過反覆重寫該特定代碼而建立起來的殘酷。 – ElectronicBlacksmith 2010-05-14 21:47:39