gantry / gantry5

:rocket: Next Generation Template / Theme Framework
http://gantry.org
1.04k stars 204 forks source link

Issue with menus if over 30 items (500 error from infinite loop) #3266

Open uglyeoin opened 2 months ago

uglyeoin commented 2 months ago

Here's a full description including troubleshooting:

https://rockettheme.com/forum/general-discussion/290948-gantry-is-500-error-if-i-add-a-child-to-the-menu?start=10#1458610

If there are over 30 items and a 2 column menu the site crashes.

AbstractMenu.php, sortAll() function sequence in this scenario:

Before it errors it's trying to $instance->sortAll(); the $instance that's set is line 316, 'Get menu items from the CMS.'

This is what calls setGroupToChildren, line 649 $item = $this->items[$key]; if (!$ordering) { $this->setGroupToChildren($item);

        return;
    }

And then this is that function, on line 700, where it infinitely loops (seemingly, only if there's more than 30 items in the current child group): protected function setGroupToChildren($item) { $groups = $item->groups(); foreach ($groups as $group => $children) { foreach ($children as $child) { $child->group = $group; $this->setGroupToChildren($child); } } }

Weirdly adding a third column but not populating it solves the issue. BUT... doing that creates a copy of a parent menu item in the third column for some reason.

uglyeoin commented 2 months ago

To add some further detail. Although making 3 columns works. As soon as we add a new menu item as a child to that menu, it stays as 3 columns, but it pushes all of the items back into the first 2 columns again. It then puts "contact us" as a duplicate in the third column for some reason. Weird glitch.

uglyeoin commented 2 months ago

Further information, even with 3 columns we reach a limit of 34 items. After 35 the system crashes again.