节点表单上的另一个保存按钮

时间:2013-01-07 09:32:27

标签: drupal-6 cck

我想添加一个按钮" 保存并添加更多"节点添加表单 drupal 6 。 单击此按钮页面应在保存节点后重定向到同一节点添加表单。 我有一个内容类型的孩子添加Child,用户可能有多个孩子,所以如果他/她想要添加另一个孩子,他/她将点击"保存并添加更多"并且用户只有一个他/她将点击的孩子"保存" 所以基本上只有重定向才能改变新按钮。

1 个答案:

答案 0 :(得分:0)

您需要创建一个包含两个文件的简单模块来执行此操作。在/ 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');
}

创建这些文件后,导航到模块页面并启用“添加更多”模块。

就是这样。您将看到一个新的“保存并添加更多”按钮,该按钮可以在子节点创建和编辑表单上执行此操作。