7

I am trying to add a menu for my module in the admin panel. I want to add it like Grand Parent > Parent > Child structure. I have used below code in my menu.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Vendor_Module::jsutariya" title="Grand Parent" module="Vendor_Module" sortOrder="100" resource="Vendor_Module::jsutariya" />
        <add id="Vendor_Module::listgallery" title="Parent" module="Vendor_Module" sortOrder="10" resource="Vendor_Module::listgallery" parent="Vendor_Module::jsutariya" />
        <add id="Vendor_Module::settings" title="Child" module="Vendor_Module"
             sortOrder="40" action="adminhtml/system_config/edit/section/list_gallery"
             resource="Vendor_Module::settings" parent="Vendor_Module::listgallery"/>
    </menu>
</config>

But I can only see Grand parent and child menus. Please check below screenshot. enter image description here

3

Honestly, I didn't give the proper answer to your question. But found a way to show the parent menu. Actually, Magento is hiding First "parent" menu via CSS. So you need to add another parent menu and will display your previous parent menu. Here is my code:

    <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
        <menu>
            <add id="Vendor_Module::jsutariya" title="Grand Parent" module="Vendor_Module" sortOrder="100" resource="Vendor_Module::jsutariya" />
            <add id="Vendor_Module::jsutariya_listgallery" title="Parent" module="Vendor_Module" sortOrder="10" resource="Vendor_Module::listgallery" parent="Vendor_Module::jsutariya" />
            <add id="Vendor_Module::jsutariya_settings" title="Child" module="Vendor_Module"
                 sortOrder="40" action="adminhtml/system_config/edit/section/list_gallery"
                 resource="Vendor_Module::settings" parent="Vendor_Module::jsutariya_listgallery"/>
            <add id="Vendor_Module::jsutariya_listgallery1" title="Another Parent" module="Vendor_Module" sortOrder="20" resource="Vendor_Module::listgallery" parent="Vendor_Module::jsutariya" />
        </menu> 
</config>

The main culprit is the following CSS and I don't know why its added in the first place by Magento

.admin__menu .level-0 > .submenu > ul > .level-1:only-of-type > .submenu-group-title {
    display: none;
}
  • 2
    Thanks Shankar. I wonder why Magento kept it hidden. Users will get confused by this because they will only see Settings and will wonder to which module it is related to. – Jaimin Sutariya Apr 7 at 13:03
6

After research a lot. I found that it is a not default Magento Bug But it is a feature!

Actually, you can not see parent title because you have a single group.

Let's understand with an example :

In your custom module, you have created Grand menu > Parent menu > Child menu

So in above Parent menu is a single group (You have only a single parent menu).

But if you create another group menu under Grand menu like : Grand menu > Parent menu 2 > Child menu

So here you have created 2 Parent menu (1) is Parent menu & (2) Parent menu 2 so basically it is 2 groups. if menu group is more then 1 group then Parent menu will display. It will not display if you have only single group menu.

Magento Core Example :

Go to Admin > Content there is 2 groups Elements and Design

So it's parent menu is displaying. check below screen shoot.

enter image description here

But Go to Admin > Sales there is only single group Sales so parent menu is not displaying.

Conclusion : If you want to display parent menu then you have to create 2 groups in the menu. Like above screenshot.

Let me know if you have any query/concern in the above explanation. I hope it helps!

3
+50

You have to need change _menu.less for fix the child menu issue actually Admin Navigation Menu labels hide in css.

You can change below _menu.less file path and comment code which is already display:none.

File path:

magento/vendor/magento/theme-adminhtml-backend/Magento_Backend/web/css/source/module/_menu.less

//  This part hides Submenu Group Titles only for menus with single groups.
    /*.submenu .column:only-of-type .submenu-group-title,
    .level-0 > .submenu > ul > .level-1:only-of-type > .submenu-group-title {
        display: none;
    }*/

For more Details refer below links:

https://github.com/magento/magento2/issues/13707

https://github.com/magento/magento2/commit/d91e96b529e70dcec55d3b5336b471791dc42d54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.