drupal 6のノード追加フォームに「保存してさらに追加」ボタンを追加したい。このボタンページをクリックすると、ノードを保存した後、同じノード追加フォームにリダイレクトされます。子を追加するコンテンツ タイプの子があります。ユーザーは複数の子を持っている可能性があるため、別の子を追加する場合は、[保存してさらに追加] をクリックし、ユーザーは子を 1 つだけクリックします。 「保存」では、基本的にリダイレクトのみが新しいボタンに変更されます。
1 に答える
0
これを行うには、2 つのファイルを含む単純なモジュールを作成する必要があります。/sites/all/modules/custom フォルダに新しいディレクトリ「addmore」を作成し (フォルダが存在しない場合は作成します)、そのディレクトリに次のファイルを作成します。
- addmore.info
- addmore.module
addmore.info の内容:
name = "Add More"
description = Create and Add More button on Child node forms
package = Other
core = 6.x
addmore.module の内容 (「Child」コンテンツタイプのマシン名を「child」と仮定)
<?php
/**
* Implementation of HOOK_form_alter
*
* For 'child' node forms, add a new button to the bottons array that submits
* and saves the node, but redirects to the node/add/child form instead of to
* the newly created node.
*/
function addmore_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'child_node_form') {
$form['buttons']['save_and_add_more'] = array(
'#type' => 'submit',
'#value' => t('Save and add more'),
'#weight' => 20,
'#submit' => array(
// Adds the existing form submit function from the regular "Save" button
$form['buttons']['submit']['#submit'][0],
// Add our custom function which will redirect to the node/add/child form
'addmore_add_another',
),
);
}
}
/**
* Custom function called when a user saves a "child" node using the "Save and
* add more" button. Directs users to node/add/child instead of the newly
* created node.
*/
function addmore_add_another() {
drupal_goto('node/add/child');
}
これらのファイルを作成したら、モジュール ページに移動し、[さらに追加] モジュールを有効にします。
それでおしまい。子ノードの作成と編集フォームでそれを行う新しい「保存してさらに追加」ボタンが表示されます。
于 2013-01-17T10:35:45.790 に答える