summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-08-09 11:01:00 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-08-09 11:01:00 +0000
commit509d570bbdc383c0d8b72c0ce5dd33fa4dc56560 (patch)
tree35792f1f17cd42af6324f6601fdd462ece47dbf5 /modules
parent51b02213310345ed754d635cdd834faa415225cd (diff)
downloadbrdo-509d570bbdc383c0d8b72c0ce5dd33fa4dc56560.tar.gz
brdo-509d570bbdc383c0d8b72c0ce5dd33fa4dc56560.tar.bz2
#160039 by prakashp, chx and pwolanin: fix node saving:
- centralize/reuse some node form saving code - fix uploads without JS - fix reappearing teasers on node save
Diffstat (limited to 'modules')
-rw-r--r--modules/book/book.module24
-rw-r--r--modules/node/node.module58
-rw-r--r--modules/upload/upload.module2
3 files changed, 39 insertions, 45 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index 4d81375e6..11b11d258 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -343,7 +343,12 @@ function book_form_alter(&$form, $form_state, $form_id) {
$form['book']['pick-book'] = array(
'#type' => 'submit',
'#value' => t('Change book (update list of parents)'),
- '#submit' => array('book_pick_book_submit'),
+ // Submit the node form so the parent select options get updated.
+ // This is typically only used when JS is disabled. Since the parent options
+ // won't be changed via AJAX, a button is provided in the node form to submit
+ // the form and generate options in the parent select corresponding to the
+ // selected book. This is similar to what happens during a node preview.
+ '#submit' => array('node_form_submit_build_node'),
'#weight' => 20,
);
}
@@ -351,23 +356,6 @@ function book_form_alter(&$form, $form_state, $form_id) {
}
/**
- * Submit the node form so the parent select options get updated.
- *
- * This is typically only used when JS is disabled. Since the parent options
- * won't be changed via AJAX, a button is provided in the node form to submit
- * the form and generate options in the parent select corresponding to the
- * selected book. This is similar to what happens during a node preview.
- */
-function book_pick_book_submit($form, &$form_state) {
- // Unset any button-level handlers, execute all the form-level submit functions
- // to process the form values into an updated node, and rebuild the form.
- unset($form_state['submit_handlers']);
- form_execute_handlers('submit', $form, $form_state);
- $form_state['rebuild'] = TRUE;
- $form_state['node'] = $form_state['values'];
-}
-
-/**
* Build the parent selection form element for the node form or outline tab
*
* This function is also called when generating a new set of options during the
diff --git a/modules/node/node.module b/modules/node/node.module
index 4a6b45265..01b2b1280 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -2231,15 +2231,23 @@ function node_form(&$form_state, $node) {
return $form;
}
-function node_form_build_preview($form, &$form_state) {
- // Unset any button-level handlers, execute all the form-level submit functions
- // to process the form values into an updated node, and rebuild the form.
+/**
+ * Build a node by processing submitted form values and prepare for a form rebuild.
+ */
+function node_form_submit_build_node($form, &$form_state) {
+ // Unset any button-level handlers, execute all the form-level submit
+ // functions to process the form values into an updated node.
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
-
- $form_state['node_preview'] = node_preview((object)$form_state['values']);
+ $node = node_submit($form_state['values']);
+ $form_state['node'] = (array)$node;
$form_state['rebuild'] = TRUE;
- $form_state['node'] = $form_state['values'];
+ return $node;
+}
+
+function node_form_build_preview($form, &$form_state) {
+ $node = node_form_submit_build_node($form, $form_state);
+ $form_state['node_preview'] = node_preview($node);
}
function theme_node_form($form) {
@@ -2391,32 +2399,30 @@ function theme_node_log_message($log) {
function node_form_submit($form, &$form_state) {
global $user;
- // Unset any button-level handlers, and execute all the form-level submit
- // functions to process the form values into an updated node.
- unset($form_state['submit_handlers']);
- form_execute_handlers('submit', $form, $form_state);
-
- // Fix up the node when required:
- $node = node_submit($form_state['values']);
+ $node = node_form_submit_build_node($form, $form_state);
+ $insert = empty($node->nid);
+ node_save($node);
+ $node_link = l(t('view'), 'node/'. $node->nid);
+ $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
+ $t_args = array('%post' => node_get_types('name', $node));
- // Prepare the node's body:
- if ($node->nid) {
- node_save($node);
- watchdog('content', '@type: updated %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
- drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node))));
+ if ($insert) {
+ watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
+ drupal_set_message(t('Your %post has been created.', $t_args));
}
else {
- node_save($node);
- watchdog('content', '@type: added %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
- drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node))));
+ watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
+ drupal_set_message(t('The %post has been updated.', $t_args));
}
if ($node->nid) {
- if (node_access('view', $node)) {
- $form_state['redirect'] = 'node/'. $node->nid;
- }
+ unset($form_state['rebuild']);
+ $form_state['redirect'] = 'node/'. $node->nid;
+ }
+ else {
+ // In the unlikely case something went wrong on save, the node will be
+ // rebuilt and node form redisplayed the same way as in preview.
+ drupal_set_message(t('The node could not be saved.'), 'error');
}
- // it is very unlikely we get here
- return FALSE;
}
/**
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index d56b5b967..0b32f29e2 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -493,7 +493,7 @@ function _upload_form($node) {
'#name' => 'attach',
'#ahah_path' => 'upload/js',
'#ahah_wrapper' => 'attach-wrapper',
- '#submit' => array(),
+ '#submit' => array('node_form_submit_build_node'),
);
}