| 1 |
<?php
|
| 2 |
// $Id: submitagain.module,v 1.1 2007/01/04 23:37:15 mfredrickson Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Add a new button to node creation forms that
|
| 7 |
* allows the content author to return to the node
|
| 8 |
* creation form after saving new content instead
|
| 9 |
* of going to the view page of the new content.
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_form_alter().
|
| 14 |
*/
|
| 15 |
function submitagain_form_alter(&$form, $form_state, $form_id) {
|
| 16 |
|
| 17 |
if (strpos($form_id, '_node_form') && !isset($form['nid']['#value'])) {
|
| 18 |
if (variable_get('submitagain_'. $form['type']['#value'], false)) {
|
| 19 |
|
| 20 |
$form['buttons']['submit_again'] = array(
|
| 21 |
'#type' => 'submit',
|
| 22 |
'#value' => t('Save and create another'),
|
| 23 |
'#weight' => 41,
|
| 24 |
'#submit' => array('node_form_submit')
|
| 25 |
);
|
| 26 |
$form['#theme'] = 'submitagain_node_form';
|
| 27 |
}
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
* Alter content type settings to add "Submit Again?" checkbox
|
| 33 |
*/
|
| 34 |
function submitagain_form_node_type_form_alter(&$form, &$form_state) {
|
| 35 |
if (isset($form['identity']['type'])) {
|
| 36 |
$form['submission']['submitagain'] = array(
|
| 37 |
'#type' => 'checkbox',
|
| 38 |
'#title' => t('Submit Again?'),
|
| 39 |
'#default_value' => variable_get('submitagain_'. $form['#node_type']->type, false),
|
| 40 |
'#description' => t('Enable this checkbox if you want to provide a "Save and create another" button for your users.')
|
| 41 |
);
|
| 42 |
}
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Implementation of hook_nodeapi().
|
| 47 |
*/
|
| 48 |
function submitagain_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
| 49 |
if ($op == 'insert' && $node->op == t('Save and create another')) {
|
| 50 |
theme('submitagain_message', $node);
|
| 51 |
drupal_goto('node/add/'. $node->type);
|
| 52 |
}
|
| 53 |
}
|
| 54 |
|
| 55 |
/**
|
| 56 |
* Impelementation of hook_theme().
|
| 57 |
*
|
| 58 |
* @return array
|
| 59 |
*/
|
| 60 |
function submitagain_theme() {
|
| 61 |
return array(
|
| 62 |
'submitagain_message' => array(
|
| 63 |
'arguments' => array('node' => NULL)
|
| 64 |
),
|
| 65 |
'submitagain_node_form' => array(
|
| 66 |
'arguments' => array('form' => array())
|
| 67 |
)
|
| 68 |
);
|
| 69 |
}
|
| 70 |
|
| 71 |
/**
|
| 72 |
* Displays a message and link to the added/edited node after submit
|
| 73 |
*/
|
| 74 |
function theme_submitagain_message(&$node) {
|
| 75 |
$link = l(url('node/'. $node->nid), 'node/'. $node->nid);
|
| 76 |
drupal_set_message(t('You may visit your post at !link', array('!link' => $link)));
|
| 77 |
}
|
| 78 |
|
| 79 |
/**
|
| 80 |
* A copy of the 'theme_node_form' function with the addition of the new button.
|
| 81 |
* Borrowed from diff.module.
|
| 82 |
*
|
| 83 |
* @return string
|
| 84 |
*/
|
| 85 |
function theme_submitagain_node_form($form) {
|
| 86 |
$output = "\n<div class=\"node-form\">\n";
|
| 87 |
|
| 88 |
$admin = '';
|
| 89 |
if (isset($form['author'])) {
|
| 90 |
$admin .= " <div class=\"authored\">\n";
|
| 91 |
$admin .= drupal_render($form['author']);
|
| 92 |
$admin .= " </div>\n";
|
| 93 |
}
|
| 94 |
if (isset($form['options'])) {
|
| 95 |
$admin .= " <div class=\"options\">\n";
|
| 96 |
$admin .= drupal_render($form['options']);
|
| 97 |
$admin .= " </div>\n";
|
| 98 |
}
|
| 99 |
$buttons = drupal_render($form['buttons']['submit']);
|
| 100 |
$buttons .= isset($form['buttons']['submit_again']) ? drupal_render($form['buttons']['submit_again']) : '';
|
| 101 |
$buttons .= drupal_render($form['buttons']['preview']);
|
| 102 |
$buttons .= isset($form['buttons']['delete']) ? drupal_render($form['buttons']['delete']) : '';
|
| 103 |
|
| 104 |
$output .= " <div class=\"standard\">\n";
|
| 105 |
$output .= drupal_render($form);
|
| 106 |
$output .= " </div>\n";
|
| 107 |
|
| 108 |
if (!empty($admin)) {
|
| 109 |
$output .= " <div class=\"admin\">\n";
|
| 110 |
$output .= $admin;
|
| 111 |
$output .= " </div>\n";
|
| 112 |
}
|
| 113 |
$output .= $buttons;
|
| 114 |
$output .= "</div>\n";
|
| 115 |
|
| 116 |
return $output;
|
| 117 |
}
|