summaryrefslogtreecommitdiff
path: root/modules/book
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-07-07 01:07:33 +0000
committerDries Buytaert <dries@buytaert.net>2010-07-07 01:07:33 +0000
commit63312b2950d2a29c852325d690320610de4dd7d5 (patch)
treeeb2cfc481152f49f81ffda17c2a506c67a93ef18 /modules/book
parent16eb932fcd8149171794a72b9e6f384eb12d2867 (diff)
downloadbrdo-63312b2950d2a29c852325d690320610de4dd7d5.tar.gz
brdo-63312b2950d2a29c852325d690320610de4dd7d5.tar.bz2
- Patch #825330 by rfay, katbailey: make book module use standard D7 AJAX forms techniques.
Diffstat (limited to 'modules/book')
-rw-r--r--modules/book/book.module31
-rw-r--r--modules/book/book.pages.inc32
2 files changed, 21 insertions, 42 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index 9c8cd6815..7651a7aa6 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -189,13 +189,6 @@ function book_menu() {
'type' => MENU_CALLBACK,
'file' => 'book.pages.inc',
);
- $items['book/js/form'] = array(
- 'page callback' => 'book_form_update',
- 'delivery callback' => 'ajax_deliver',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- 'file' => 'book.pages.inc',
- );
return $items;
}
@@ -481,6 +474,8 @@ function _book_parent_select($book_link) {
'#description' => t('The parent page in the book. The maximum depth for a book and all child pages is !maxdepth. Some pages in the selected book may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
'#options' => book_toc($book_link['bid'], $book_link['parent_depth_limit'], array($book_link['mlid'])),
'#attributes' => array('class' => array('book-title-select')),
+ '#prefix' => '<div id="edit-book-plid-wrapper">',
+ '#suffix' => '</div>',
);
}
@@ -491,8 +486,11 @@ function _book_parent_select($book_link) {
* Build the common elements of the book form for the node and outline forms.
*/
function _book_add_form_elements(&$form, &$form_state, $node) {
- // Need this for AJAX.
- $form_state['cache'] = TRUE;
+ // If the form is being processed during the AJAX callback of our book bid
+ // dropdown, then $form_state will hold the value that was selected.
+ if (isset($form_state['values']['book'])) {
+ $node->book = $form_state['values']['book'];
+ }
$form['book'] = array(
'#type' => 'fieldset',
@@ -557,7 +555,7 @@ function _book_add_form_elements(&$form, &$form_state, $node) {
'#weight' => -5,
'#attributes' => array('class' => array('book-title-select')),
'#ajax' => array(
- 'path' => 'book/js/form',
+ 'callback' => 'book_form_update',
'wrapper' => 'edit-book-plid-wrapper',
'effect' => 'fade',
'speed' => 'fast',
@@ -566,6 +564,19 @@ function _book_add_form_elements(&$form, &$form_state, $node) {
}
/**
+ * Renders a new parent page select element when the book selection changes.
+ *
+ * This function is called via AJAX when the selected book is changed on a node
+ * or book outline form.
+ *
+ * @return
+ * The rendered parent page select element.
+ */
+function book_form_update($form, $form_state) {
+ return $form['book']['plid'];
+}
+
+/**
* Common helper function to handles additions and updates to the book outline.
*
* Performs all additions and updates to the book outline through node addition,
diff --git a/modules/book/book.pages.inc b/modules/book/book.pages.inc
index 1767dfe1a..3e682ef20 100644
--- a/modules/book/book.pages.inc
+++ b/modules/book/book.pages.inc
@@ -217,35 +217,3 @@ function book_remove_form_submit($form, &$form_state) {
}
$form_state['redirect'] = 'node/' . $node->nid;
}
-
-/**
- * Renders a new parent page select element when the book selection changes.
- *
- * This function is called via AJAX when the selected book is changed on a node
- * or book outline form. It creates a new parent page select element, adds it
- * to the cached form, and then returns the rendered element so it can be
- * displayed on the form.
- *
- * @return
- * The rendered parent page select element.
- */
-function book_form_update() {
- // Load the form based upon the $_POST data sent via the ajax call.
- list($form, $form_state) = ajax_get_form();
-
- $bid = $_POST['book']['bid'];
-
- // Validate the bid.
- if (isset($form['book']['bid']['#options'][$bid])) {
- $book_link = $form['#node']->book;
- $book_link['bid'] = $bid;
- // Get the new options and update the cache.
- $form['book']['plid'] = _book_parent_select($book_link);
- form_set_cache($form['values']['form_build_id'], $form, $form_state);
-
- // Build the new select element and return it.
- $form_state = array();
- $form = form_builder($form['form_id']['#value'], $form, $form_state);
- return $form['book']['plid'];
- }
-}