Commit 28385827 authored by webchick's avatar webchick

Issue #1007746 by figureone, ryanissamson, tim.plunkett | marcp: Fixed...

Issue #1007746 by figureone, ryanissamson, tim.plunkett | marcp: Fixed Reordering fails with more than 100 items in a menu.
parent cd224643
......@@ -244,6 +244,14 @@ function doMenuTests($menu_name = 'navigation') {
$this->assertMenuLink($item2['mlid'], array('depth' => 3, 'has_children' => 1, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => $item2['mlid'], 'p4' => 0));
$this->assertMenuLink($item3['mlid'], array('depth' => 4, 'has_children' => 0, 'p1' => $item4['mlid'], 'p2' => $item5['mlid'], 'p3' => $item2['mlid'], 'p4' => $item3['mlid'], 'p5' => 0));
// Add 102 menu links with increasing weights, then make sure the last-added
// item's weight doesn't get changed because of the old hardcoded delta=50
$items = array();
for ($i = -50; $i <= 51; $i++) {
$items[$i] = $this->addMenuLink(0, 'node/' . $node1->nid, $menu_name, TRUE, strval($i));
}
$this->assertMenuLink($items[51]['mlid'], array('weight' => '51'));
// Enable a link via the overview form.
$this->disableMenuLink($item1);
$edit = array();
......@@ -287,9 +295,10 @@ function testMenuQueryAndFragment() {
* @param integer $plid Parent menu link id.
* @param string $link Link path.
* @param string $menu_name Menu name.
* @param string $weight Menu weight
* @return array Menu link created.
*/
function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $expanded = TRUE) {
function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $expanded = TRUE, $weight = '0') {
// View add menu link page.
$this->drupalGet("admin/structure/menu/manage/$menu_name/add");
$this->assertResponse(200);
......@@ -302,7 +311,7 @@ function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'navigation', $e
'enabled' => TRUE, // Use this to disable the menu and test.
'expanded' => $expanded, // Setting this to true should test whether it works when we do the std_user tests.
'parent' => $menu_name . ':' . $plid,
'weight' => '0',
'weight' => $weight,
);
// Add menu link.
......
......@@ -61,6 +61,7 @@ function menu_overview_form($form, &$form_state, $menu) {
foreach ($result as $item) {
$links[] = $item;
}
$delta = max(count($links), 50);
$tree = menu_tree_data($links);
$node_links = array();
menu_tree_collect_node_links($tree, $node_links);
......@@ -69,7 +70,7 @@ function menu_overview_form($form, &$form_state, $menu) {
menu_tree_check_access($tree, $node_links);
$menu_admin = FALSE;
$form = array_merge($form, _menu_overview_tree_form($tree));
$form = array_merge($form, _menu_overview_tree_form($tree, $delta));
$form['#menu'] = $menu;
if (element_children($form)) {
......@@ -90,8 +91,10 @@ function menu_overview_form($form, &$form_state, $menu) {
*
* @param $tree
* The menu_tree retrieved by menu_tree_data.
* @param $delta
* The default number of menu items used in the menu weight selector is 50.
*/
function _menu_overview_tree_form($tree) {
function _menu_overview_tree_form($tree, $delta = 50) {
$form = &drupal_static(__FUNCTION__, array('#tree' => TRUE));
foreach ($tree as $data) {
$title = '';
......@@ -110,7 +113,7 @@ function _menu_overview_tree_form($tree) {
);
$form[$mlid]['weight'] = array(
'#type' => 'weight',
'#delta' => 50,
'#delta' => $delta,
'#default_value' => $item['weight'],
'#title_display' => 'invisible',
'#title' => t('Weight for @title', array('@title' => $item['title'])),
......@@ -138,7 +141,7 @@ function _menu_overview_tree_form($tree) {
}
if ($data['below']) {
_menu_overview_tree_form($data['below']);
_menu_overview_tree_form($data['below'], $delta);
}
}
return $form;
......@@ -352,10 +355,23 @@ function menu_edit_item($form, &$form_state, $type, $item, $menu) {
'#description' => t('The maximum depth for a link and all its children is fixed at !maxdepth. Some menu links may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
'#attributes' => array('class' => array('menu-title-select')),
);
// Get number of items in menu so the weight selector is sized appropriately.
$sql = "SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu";
$result = db_query($sql, array(':menu' => $item['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $row) {
foreach ($row as $menu_item_count) {
$delta = $menu_item_count;
}
}
if ($delta < 50) {
// Old hardcoded value.
$delta = 50;
}
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 50,
'#delta' => $delta,
'#default_value' => $item['weight'],
'#description' => t('Optional. In the menu, the heavier links will sink and the lighter links will be positioned nearer the top.'),
);
......
......@@ -704,10 +704,23 @@ function menu_form_node_form_alter(&$form, $form_state) {
'#options' => $options,
'#attributes' => array('class' => array('menu-parent-select')),
);
// Get number of items in menu so the weight selector is sized appropriately.
$sql = "SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu";
$result = db_query($sql, array(':menu' => $link['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $row) {
foreach ($row as $menu_items) {
$delta = $menu_items;
}
}
if ($delta < 50) {
// Old hardcoded value
$delta = 50;
}
$form['menu']['link']['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 50,
'#delta' => $delta,
'#default_value' => $link['weight'],
'#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
);
......
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