Magento – Magento2: Sub-menu is not appearing in admin

acladminmenumagento2

I'm using below code in adminhtml/menu.xml to show menu/sub-menu in admin. I'm able to see menu Lapisbard in admin but sub-menu Store Locations is not visible when I click on menu named Lapisbard.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Backend/etc/menu.xsd">
    <menu>
        <add id="lapisbard::base" title="Lapisbard" module="Lapisbard_StoreLocator" sortOrder="90" resource="Lapisbard_StoreLocator::storelocator" />
        <add id="lapisbard_storelocator::locations" title="Store Locations" module="Lapisbard_StoreLocator" sortOrder="10" parent="lapisbard::base" action="lapisbard_storelocator/locations/" resource="Lapisbard_StoreLocator::locations"/>
    </menu>
</config> 

If I'm adding it in content section using parent="Magento_Backend::content" it's working fine there.

<menu>
    <add id="Lapisbard_StoreLocator::storelocator" title="Lapisbard" module="Lapisbard_StoreLocator" sortOrder="90" parent="Magento_Backend::content" resource="Lapisbard_StoreLocator::storelocator" />
    <add id="Lapisbard_StoreLocator::locations" title="Store Locations" module="Lapisbard_StoreLocator" sortOrder="10" parent="Lapisbard_StoreLocator::storelocator" action="blog/post" resource="Lapisbard_StoreLocator::locations"/>
</menu>

Best Answer

I think you're missing the acl here.

     <menu>
        <add id="Company_Module::dashboard" title="Dashboard1" module="Company_Module" sortOrder="12" resource="Company_Module::dashboard"/>
        <add id="Company_Module::subdashboard" title="Subdashboard" module="Company_Module" sortOrder="12" action="company/dashboard" resource="Company_Module::dashboard" parent="Company_Module::dashboard"/>
    </menu>

and acl like:

    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Company_Module::dashboard" title="Dashboard" sortOrder="12" />
            </resource>
        </resources>
    </acl>

Basically, your problem lies in the permissions. If you inherit it from Backend, you are using the Backend's permissions, and you are fine. But if you want to have submenu, you need your own acl.