You are here

function tb_megamenu_insert_tb_item in The Better Mega Menu 7

1 call to tb_megamenu_insert_tb_item()
tb_megamenu_sync_config in ./tb_megamenu.functions.inc

File

./tb_megamenu.functions.inc, line 356

Code

function tb_megamenu_insert_tb_item(&$item_config, $row, $col, $item) {
  $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();

  // 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 && isset($new_config['weight'])) {
      $new_col[] = $new_config;
      $added = TRUE;
    }

    // Sort all cells by ascending weight value to match the menu ordering.
    $weight = [];
    foreach ($new_col as $col_key => $col_vals) {
      if (isset($col_vals['weight'])) {
        $weight[] = $col_vals['weight'];
      }
    }
    array_multisort($weight, SORT_ASC, $new_col);
  }
  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;
}