Skip to content
Snippets Groups Projects
Commit 2ebaaa10 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #272900 by pwolanin: prevent concurrent modificiations of book pages.

parent e1ef7fb3
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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'),
......@@ -82,6 +82,18 @@ function book_admin_edit($form_state, $node) {
return $form;
}
/**
* 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.
*
......@@ -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;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment