summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/book/book.admin.inc32
1 files changed, 27 insertions, 5 deletions
diff --git a/modules/book/book.admin.inc b/modules/book/book.admin.inc
index 8b5d4e6f3..088c2d68a 100644
--- a/modules/book/book.admin.inc
+++ b/modules/book/book.admin.inc
@@ -73,7 +73,7 @@ function book_admin_edit($form_state, $node) {
drupal_set_title(check_plain($node->title));
$form = array();
$form['#node'] = $node;
- $form['table'] = _book_admin_table($node);
+ _book_admin_table($node, $form);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save book pages'),
@@ -83,6 +83,18 @@ function book_admin_edit($form_state, $node) {
}
/**
+ * Check that the book has not been changed while using the form.
+ *
+ * @see book_admin_edit()
+ */
+function book_admin_edit_validate($form, &$form_state) {
+ if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) {
+ form_set_error('', t('This book has been modified by another user, the changes could not be saved.'));
+ $form_state['rebuild'] = TRUE;
+ }
+}
+
+/**
* Handle submission of the book administrative page form.
*
* This function takes care to save parent menu items before their children.
@@ -130,8 +142,8 @@ function book_admin_edit_submit($form, &$form_state) {
*
* @see book_admin_edit()
*/
-function _book_admin_table($node) {
- $form = array(
+function _book_admin_table($node, &$form) {
+ $form['table'] = array(
'#theme' => 'book_admin_table',
'#tree' => TRUE,
);
@@ -139,10 +151,20 @@ function _book_admin_table($node) {
$tree = book_menu_subtree_data($node->book);
$tree = array_shift($tree); // Do not include the book item itself.
if ($tree['below']) {
- _book_admin_table_tree($tree['below'], $form);
+ $hash = sha1(serialize($tree['below']));
+ // Store the hash value as a hidden form element so that we can detect
+ // if another user changed the book hierarchy.
+ $form['tree_hash'] = array(
+ '#type' => 'hidden',
+ '#default_value' => $hash,
+ );
+ $form['tree_current_hash'] = array(
+ '#type' => 'value',
+ '#value' => $hash,
+ );
+ _book_admin_table_tree($tree['below'], $form['table']);
}
- return $form;
}
/**