diff --git a/tb_megamenu.functions.inc b/tb_megamenu.functions.inc index c1f60b1..e02d88e 100644 --- a/tb_megamenu.functions.inc +++ b/tb_megamenu.functions.inc @@ -330,7 +330,9 @@ function tb_megamenu_sync_config($items, &$item_config, $_mlid, $section) { $row++; } tb_megamenu_insert_tb_item($item_config, $row, $col, $item); - $item_config['rows_content'][$row][$col]['col_config'] = array(); + if (!isset($item_config['rows_content'][$row][$col]['col_config'])) { + $item_config['rows_content'][$row][$col]['col_config'] = array(); + } } } } @@ -338,20 +340,29 @@ function tb_megamenu_sync_config($items, &$item_config, $_mlid, $section) { } function tb_megamenu_insert_tb_item(&$item_config, $row, $col, $item) { - $i = 0; + $added = FALSE; + $new_col = array(); $col_content = isset($item_config['rows_content'][$row][$col]['col_content']) ? $item_config['rows_content'][$row][$col]['col_content'] : array(); - while ($i < count($col_content) && $col_content[$i]['weight'] < $item['link']['weight']) { - $i++; - } - for ($j = count($col_content); $j > $i; $j--) { - $item_config['rows_content'][$row][$col]['col_content'][$j] = $item_config['rows_content'][$row][$col]['col_content'][$j - 1]; - } - $item_config['rows_content'][$row][$col]['col_content'][$i] = array( + // If this tree has not been corrected due to issue #2571547, $col_content might be an associative array. + // It should be an indexed array. Build a new indexed array, discarding the keys. + $new_config = array( 'mlid' => $item['link']['mlid'], 'type' => 'menu_item', 'weight' => $item['link']['weight'], 'tb_item_config' => array(), ); + foreach ($col_content as $cell){ + $new_col[] = $cell; + if (!$added && $new_config['weight'] >= $cell['weight']) { + $new_col[] = $new_config; + $added = TRUE; + } + } + if (!count($new_col)) { + // in case there were no existing items + $new_col[] = $new_config; + } + $item_config['rows_content'][$row][$col]['col_content'] = $new_col; } function tb_megamenu_array_to_object($array) {