summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-08-20 17:54:35 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-08-20 17:54:35 +0000
commitf4dc86046fb54ec44339eb33f68538fc8019c1b0 (patch)
tree3c77914ef798a83e7f9dbb27cf556f997d1bf61f /modules
parent580faf849dbd9968aef504f63c297b4b1ccbce78 (diff)
downloadbrdo-f4dc86046fb54ec44339eb33f68538fc8019c1b0.tar.gz
brdo-f4dc86046fb54ec44339eb33f68538fc8019c1b0.tar.bz2
#165675 follow up patch by pwolanin: retain menu information on node previews to check, do not use the newly selected values yet, to be consistent with the DB
Diffstat (limited to 'modules')
-rw-r--r--modules/book/book.module24
-rw-r--r--modules/menu/menu.module20
2 files changed, 36 insertions, 8 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index 245651d09..3a51bc4c8 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -385,15 +385,12 @@ function _book_parent_select($book_link) {
$form['#prefix'] .= '<em>'. t('No book selected.') .'</em>';
}
else {
- // If the item has children, there is an added limit to the depth of valid parents.
- $limit = MENU_MAX_DEPTH - 1 - ($book_link['has_children'] ? menu_link_children_relative_depth($book_link) : 0);
-
$form = array(
'#type' => 'select',
'#title' => t('Parent item'),
'#default_value' => $book_link['plid'],
'#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'], array($book_link['mlid']), $limit),
+ '#options' => book_toc($book_link['bid'], array($book_link['mlid']), $book_link['parent_depth_limit']),
'#attributes' => array('class' => 'book-title-select'),
);
}
@@ -422,7 +419,7 @@ function _book_add_form_elements(&$form, $node) {
'#tree' => TRUE,
'#attributes' => array('class' => 'book-outline-form'),
);
- foreach (array('menu_name', 'mlid', 'nid', 'router_path', 'has_children', 'options', 'module', 'original_bid') as $key) {
+ foreach (array('menu_name', 'mlid', 'nid', 'router_path', 'has_children', 'options', 'module', 'original_bid', 'parent_depth_limit') as $key) {
$form['book'][$key] = array(
'#type' => 'value',
'#value' => $node->book[$key],
@@ -442,7 +439,7 @@ function _book_add_form_elements(&$form, $node) {
$options = array();
$nid = isset($node->nid) ? $node->nid : 'new';
- if (isset($node->nid) && ($nid == $node->book['original_bid']) && $node->book['has_children'] && (MENU_MAX_DEPTH - 1 - menu_link_children_relative_depth($node->book) == 0)) {
+ if (isset($node->nid) && ($nid == $node->book['original_bid']) && ($node->book['parent_depth_limit'] == 0)) {
// This is the top level node in a maximum depth book and thus cannot be moved.
$options[$node->nid] = $node->title;
}
@@ -499,6 +496,10 @@ function book_outline_form(&$form_state, $node) {
else {
$node->book['original_bid'] = $node->book['bid'];
}
+ // Find the depth limit for the parent select.
+ if (!isset($node->book['parent_depth_limit'])) {
+ $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
+ }
$form['#node'] = $node;
$form['#id'] = 'book-outline';
_book_add_form_elements($form, $node);
@@ -901,11 +902,22 @@ function book_nodeapi(&$node, $op, $teaser, $page) {
$node->book['original_bid'] = $node->book['bid'];
}
}
+ // Find the depth limit for the parent select.
+ if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) {
+ $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
+ }
break;
}
}
/**
+ * Find the depth limit for items in the parent select.
+ */
+function _book_parent_depth_limit($book_link) {
+ return MENU_MAX_DEPTH - 1 - (($book_link['mlid'] && $book_link['has_children']) ? menu_link_children_relative_depth($book_link) : 0);
+}
+
+/**
* Form altering function for the confirm form for a single node deletion.
*/
function book_form_node_delete_confirm_alter(&$form, $form_state) {
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index f9ad1a31c..385732482 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -403,7 +403,12 @@ function menu_edit_item_submit($form, &$form_state) {
function menu_parent_options($menus, $item) {
// If the item has children, there is an added limit to the depth of valid parents.
- $limit = MENU_MAX_DEPTH - 1 - (($item['mlid'] && $item['has_children']) ? menu_link_children_relative_depth($item) : 0);
+ if (isset($item['parent_depth_limit'])) {
+ $limit = $item['parent_depth_limit'];
+ }
+ else {
+ $limit = _menu_parent_depth_limit($item);
+ }
foreach ($menus as $menu_name => $title) {
$tree = menu_tree_all_data($menu_name, NULL);
@@ -729,11 +734,22 @@ function menu_nodeapi(&$node, $op) {
// Set default values.
$node->menu = $item + array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu_name, 'weight' => 0, 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0, 'customized' => 0);
}
+ // Find the depth limit for the parent select.
+ if (!isset($node->menu['parent_depth_limit'])) {
+ $node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
+ }
break;
}
}
/**
+ * Find the depth limit for items in the parent select.
+ */
+function _menu_parent_depth_limit($item) {
+ return MENU_MAX_DEPTH - 1 - (($item['mlid'] && $item['has_children']) ? menu_link_children_relative_depth($item) : 0);
+}
+
+/**
* Implementation of hook_form_alter(). Adds menu item fields to the node form.
*/
function menu_form_alter(&$form, $form_state, $form_id) {
@@ -764,7 +780,7 @@ function menu_form_alter(&$form, $form_state, $form_id) {
$form['menu']['#collapsed'] = TRUE;
}
- foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden') as $key) {
+ foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden', 'parent_depth_limit') as $key) {
$form['menu'][$key] = array('#type' => 'value', '#value' => $item[$key]);
}