Commit f4dc8604 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#165675 follow up patch by pwolanin: retain menu information on node previews...

#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
parent 580faf84
......@@ -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,10 +902,21 @@ 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.
*/
......
......@@ -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,10 +734,21 @@ 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.
*/
......@@ -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]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment