diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-06-17 13:44:45 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-06-17 13:44:45 +0000 |
commit | cb043e8c489f033f7435e7fd5d18325155465c77 (patch) | |
tree | 716cdfe743aa99a01a1dce97cc800c00119af896 /modules/book/book.module | |
parent | 3620310d7c8a5d487f7b6826a89f8a4816149333 (diff) | |
download | brdo-cb043e8c489f033f7435e7fd5d18325155465c77.tar.gz brdo-cb043e8c489f033f7435e7fd5d18325155465c77.tar.bz2 |
- Patch #735800 by effulgentsia, fago, Frando: node form triggers form level submit functions on button level submits, without validation. Oh yeah.
Diffstat (limited to 'modules/book/book.module')
-rw-r--r-- | modules/book/book.module | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/modules/book/book.module b/modules/book/book.module index bea4a077f..9d3284bc8 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -416,15 +416,13 @@ function book_form_alter(&$form, &$form_state, $form_id) { if ($access) { _book_add_form_elements($form, $form_state, $node); + // Since the "Book" dropdown can't trigger a form submission when + // JavaScript is disabled, add a submit button to do that. book.css hides + // this button when JavaScript is enabled. $form['book']['pick-book'] = array( '#type' => 'submit', '#value' => t('Change book (update list of parents)'), - // 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'), + '#submit' => array('book_pick_book_nojs_submit'), '#weight' => 20, ); } @@ -432,6 +430,22 @@ function book_form_alter(&$form, &$form_state, $form_id) { } /** + * Submit handler to change a node's book. + * + * This handler is run when JavaScript is disabled. It triggers the form to + * rebuild so that the "Parent item" options are changed to reflect the newly + * selected book. When JavaScript is enabled, the submit button that triggers + * this handler is hidden, and the "Book" dropdown directly triggers the + * book_form_update() AJAX callback instead. + * + * @see book_form_update() + */ +function book_pick_book_nojs_submit($form, &$form_state) { + $form_state['node']->book = $form_state['values']['book']; + $form_state['rebuild'] = TRUE; +} + +/** * 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 |