t3framework / t3

T3 Framework - (Core Plugin & Blank Template)
GNU General Public License v2.0
273 stars 160 forks source link

Hidden sub-menue item breaks menu-structur #522

Open HoozeMe opened 6 years ago

HoozeMe commented 6 years ago

If the last submenu item is set to 'hidden' (not shown), the ul/li - stuctur is broken Threfore I added the closing statment before continue:

if ($menu_show!=1) {
    // ** ... Hack fixing the problem of a last item that is hidden 
    if ($item->shallower) 
        echo str_repeat('</ul></li>', $item->level_diff);
    // ***
continue;
}

Now ist works, but ... ... if there is only one sub-item and this is hidden, the 'caret' is still shown.

To fix this 'quick and dirty' I compare in the type-functions a small hint from the menu-item-note.

if($item->deeper && $item->level < 2 && strpos($item->note, 'NODEEP') === false ){
    $class    .= ' dropdown-toggle';
    $dropdown  = ' data-toggle="dropdown"';
    $caret     = '<em class="caret"></em>';
}

My changes work ;) ... but only until the next update.

I propose a recursive buildup of the menu instead of the linear one in the function render($list). Then you know exactly whether an item is displayed and whether whole submenus may be empty and no dropdowns are to be displayed (not use $item->deeper, this could be hidden).

HoozeMe commented 5 years ago

Sorry for late answer ... today an update of T3 reminded me of that bug. I try to prepare an environment with that problem - but I had to fix it on our live-website immediately.

Here some screenshots... This is the menu configuration: menu configuration

'Kinder', 'Music' are 1st level entries; but because of the hidden entry they are put below the 'Gemeinde'-Entry

So it looks with original code: broken menue

So it looks with my hack: Almost okay :) menue with fix

grantg182 commented 4 years ago

This issue still exists. Hack fix as above works, but not really a solution.

altcom-neil commented 3 years ago

Hi, Just spent hours trying to work out why my menu was suddenly broken after turning off MegaMenu which seems to hide the bug.

They have added:

//intergration with new params joomla 3.6.x (menu_show)
$menu_show = (int)$item->params->get('menu_show', 1);
if ($menu_show!=1)
    continue;

to T3BootstrapTpl::render() but this is the wrong place for this code - by now the array of menu items should just be rendered. If you compare the code with how the core ModMenuHelper::getList() works the array of menu items should already have excluded the hidden menu item before passing it to the render function. The code above should be removed from T3BootstrapTpl::render() and instead the correct code mirroring how ModMenuHelper::getList() works should be added to T3Bootstrap::getList()

Here is the git patch for the file in our site: T3Bootstrap-fix-hidden-sub-menu-item-bug.patch.txt

It adds the $hidden_parents array:

    // Get active menu item
    $items = $menu->getItems('menutype', $this->menutype);
    $hidden_parents = array(); // Bug fix for issue 522
    $lastitem = 0;

plus adds exactly the same menu_show check as the core file before the $item->parent = ... line :

            // Exclude item with menu item option set to exclude from menu modules - Bug fix for issue 522
            if (($item->params->get('menu_show', 1) == 0) || in_array($item->parent_id, $hidden_parents))
            {
                $hidden_parents[] = $item->id;
                unset($items[$i]);
                continue;
            }

This fixes the broken menu html for our site.

grantg182 commented 3 years ago

Thanks @altcom-neil - I've committed this to master here though judging by outstanding PR's, I doubt this will ever get merged 😞