Hello I had the following issue:
Notice: Undefined offset: 6 i tb_megamenu_insert_tb_item()
row 347

When i looked at row 346 i saw that $col_content variable could either have a value in it, or be an empty array = array();
and in 347 that array was used to query inside it, but it does not take into consideration that the value could be empty array, in that case we should not query at all.
so I put the code inside a condition that the variable cannot be empty. and the notice goes away.

so now it looks like this:

<?php
function tb_megamenu_insert_tb_item(&$item_config, $row, $col, $item) {
  $i = 0;
  $col_content = isset($item_config['rows_content'][$row][$col]['col_content']) ? $item_config['rows_content'][$row][$col]['col_content'] : array();
  if(!$col_content) {  //this statement is new
    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];
    }
  } //closing if statement
    $item_config['rows_content'][$row][$col]['col_content'][$i] = array(
      'mlid' => $item['link']['mlid'],
      'type' => 'menu_item',
      'weight' => $item['link']['weight'],
      'tb_item_config' => array(),
    );

}

?>

I wonder if this could be added to the next release?

Thanks,
/K

Comments

Anonymous’s picture

Issue summary: View changes
Anonymous’s picture

Issue summary: View changes
Anonymous’s picture

That change created new issues, so if none else is seeing this then it has to be my configuration, If i find something else i will bring it up.

Anonymous’s picture

Status: Active » Postponed
sagar ramgade’s picture

Hi,

We also faced the same issue, here is the solution in the form of patch file.

sagar ramgade’s picture

I still noticed that errors were getting logged in watchdog, so created a different patch.

broeker’s picture

Regarding the patch in #6 -- it only works if you have the module in sites/all:

--- a/sites/all/modules/tb_megamenu/tb_megamenu.functions.inc
+++ b/sites/all/modules/tb_megamenu/tb_megamenu.functions.inc

should be:

--- a/tb_megamenu/tb_megamenu.functions.inc
+++ b/tb_megamenu/tb_megamenu.functions.inc

Don't have time to reroll at the moment but will let you know if the patch works for us -- we are also seeing this error.

broeker’s picture

FYI when we applied this patch we were only seeing the last menu item for all top-level parent menu items, e.g.

My Menu
* Link One
* Link Two
* Link Three (Only this one shows)

With the patch reverted things go back to normal and all menu links show.

ki’s picture

Fixed error of #6 reported in #8.

danepowell’s picture

Title: Notice: Undefined offset: 6 i tb_megamenu_insert_tb_item() row 347 » Notice: Undefined offset in tb_megamenu_insert_tb_item()
Status: Postponed » Needs review
StatusFileSize
new2.13 KB

@Ki patches need to be made relative to the project root, not your Drupal root. See the patch guide: https://www.drupal.org/node/707484

This is the same code as #9 but formatted correctly.

danepowell’s picture

StatusFileSize
new1.75 KB
new444 bytes

Looks like the whitespace cleanup in #10 conflicts with another patch, I'll remove it.

Alestaan’s picture

I applied the patch because i got the same error as kentoro and now, i got the following error:

"Notice : Undefined offset: 0 in tb_megamenu_sync_config() (line 329 in \tb_megamenu\tb_megamenu.functions.inc)."

Any thought ?

sittard’s picture

Same issue here after upgrading to PHP 5.6.16

Undefined offset: 0 in tb_megamenu_sync_config() (line 329 tb_megamenu/tb_megamenu.functions.inc)

maatthieu’s picture

Hi I just got exactly the same error ("Notice : Undefined offset: 0 in tb_megamenu_sync_config() (line 329 in \tb_megamenu\tb_megamenu.functions.inc)."). Then I went to "structure>TB Mega Menu" to configure the menu ; I just change create a new column inside the seconde menu then saved it. And the notice disappeared.

tedfordgif’s picture

The last patch also has an issue.

  1. It shouldn't be checking that index $j is set, which could cause the last item in the array to be lost/overwritten.
  2. Another alternative is to use array_splice() instead of the second for loop. This function assumes the array keys are numeric and start from 0, so it seems like a safe change.
lanceh1412’s picture

Looks like this issue is a duplicate of this one. I was getting the same problem. The solution in #3 of that issue seems to work for me. This error did actually take my site offline as suggested was possible in #10 of that issue. It was only by disabling the module that i was able to get the site up and running again.

nevergone’s picture

Status: Needs review » Closed (duplicate)