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'] = 配列( 'タイトル' => '著者を追加', 'ページ コールバック' => 'get_author_form', '引数にアクセス' => array('コンテンツにアクセス'), 'file' => 'author.pages.inc', );
このコードを呼び出します
関数 get_author_form() { //return node_form(NULL,NULL); //return drupal_get_form('author_form'); return author_ajax_form('作者'); } 関数 author_ajax_form($type) { グローバル $user; 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, ' language' => 'bbb','bbb' => 'TRUE'); $output = drupal_get_form($type .'_node_form', $node); } $出力を返します。 }
そして、ここに hook_form と hook_form_alter コードがあります
function author_form_author_node_form_alter(&$form, &$form_state) { $form['author']=NULL; $form['分類法']=NULL; $form['options']=NULL; $form['メニュー']=NULL; $form['comment_settings']=NULL; $form['files']=NULL; $form['revision_information']=NULL; $form['attachments']=NULL; if($form["qqq"]) { $form['buttons']['preview']=NULL; } } 関数 author_form(&$node) { return make_author_form(&$node); } function make_author_form(&$node) { グローバル $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'] = 配列( '#type' => 'フィールドセット', '#タイトル' => t('作者'), '#weight' => -50, '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['author_id'] = 配列( '#access' => user_access('pd_recluse エントリの作成'), '#type' => 'hidden', '#default_value' => $node->author_id, '#体重' => -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'] = 配列( '#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' => 'テキストエリア', '#title' => '著者の説明', '#default_value' => $node->body, '#required' => FALSE, '#体重' => -19 ); $form['status'] = 配列( '#type' => 'hidden', '#default_value' => '1' ); $form['promote'] = 配列( '#type' => 'hidden', '#default_value' => '1' ); $form['name'] = 配列( '#type' => 'hidden', '#default_value' => $user->名前 ); $form['format'] = 配列( '#type' => 'hidden', '#default_value' => '1' ); // node_example には、この単純な node-type には不要な追加コードがいくつかあることに注意してください $thepath='ミラノ/著者'; if($_REQUEST["手紙"]) { $thepath .= "/" . $_REQUEST["手紙"]; } if($ノード['言語']) { $thepath='milan/authorajaxclose'; $form['qqq'] = 配列( '#type' => 'hidden', '#default_value' => '1' ); } $form['#redirect'] = $thepath; $フォームを返します。 }
そのメニュー パスは、このテーマ (PHPTemplate) と一致します。