Our brands

How to create menu in Magento 2 admin

magento-2-admin- menu

My previous tutorial show you how to create a simple module in Magento 2, learn more here: http://www.venustheme.com/how-to-create-magento-2-module/. Today, we continue discuss about Magento 2 admin menu.

In Magento 1, menu configuration are located inside etc/adminhtml.xml but in Magento 2 menu configuration are located in etc/adminhtml/menu.xml file

<?xml version=”1.0″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../../Backend/etc/menu.xsd”>
<menu>
<add id=”Ves_Brand::brand” title=”Venustheme” module=”Ves_Brand” sortOrder=”20″ resource=”Ves_Brand::brand”/>
<add id=”Ves_Brand::brand” title=”Brand” module=”Ves_Brand” sortOrder=”40″ resource=”Ves_Brand::brand” parent=”Ves_Brand::brand”/>
<add id=”Ves_Brand::brand_new” title=”Add New Brand” module=”Ves_Brand” sortOrder=”10″ parent=”Ves_Brand::brand” action=”vesbrand/brand/new” resource=”Ves_Brand::brand”/>
<add id=”Ves_Brand::brand_manage” title=”Manage Brands” module=”Ves_Brand” sortOrder=”20″ parent=”Ves_Brand::brand” action=”vesbrand/brand/index” resource=”Ves_Brand::brand”/>
<add id=”Ves_Brand::brand_group_add_new” title=”Add New Group” module=”Ves_Brand” sortOrder=”30″ parent=”Ves_Brand::brand” action=”vesbrand/group/new” resource=”Ves_Brand::group”/>
<add id=”Ves_Brand::brand_group_manage” title=”Manage Groups” module=”Ves_Brand” sortOrder=”40″ parent=”Ves_Brand::brand” action=”vesbrand/group/index” resource=”Ves_Brand::group”/>
<add id=”Ves_Brand::configuration” title=”Configuration” module=”Ves_Brand” sortOrder=”50″
parent=”Ves_Brand::brand” action=”adminhtml/system_config/edit/section/vesbrand” resource=”Ves_Brand::config_brand”/>
</menu>
</config>

The first line:

<add id=”Ves_Brand::brand” title=”Venustheme” module=”Ves_Brand” sortOrder=”20″ resource=”Ves_Brand::brand”/>

It is the root parent of your customer menu because you haven’t declared the parent attribute. The title equal what you want show as title for root tag, id need unique, the resource you need inside acl.xml(when you want manage permission for your module)

The second line:

<add id=”Ves_Brand::brand” title=”Brand” module=”Ves_Brand” sortOrder=”40″ resource=”Ves_Brand::brand” parent=”Ves_Brand::brand”/>

It’s child of Ves_HelloWorld::brand, if you see parent=”Ves_HelloWorld::brand”, you can consider as container include links child

The third line:

<add id=”Ves_Brand::brand_new” title=”Add New Brand” module=”Ves_Brand” sortOrder=”10″ parent=”Ves_Brand::brand” action=”vesbrand/brand/new” resource=”Ves_Brand::brand”/>

It’s child of container Ves_HelloWorld::brand_head_manage, with property action=”veshelloworkd/brand/new” the veshelloworld is the frontName of admin – it declared in file etc/adminhtml/routes.xml, brand is a folder inside Controller/Adminhtml, Magento 2 give you the default action Index.php(the file contain the execute() function), but you can add more file such as Edit.php with action=”veshelloworkd/brand/edit”

Magento 2 Tutorials & Magento 2 Extensions

Share this Post!

Alena Dao
Alena Dao
“Good marketing makes the company look smart. Great marketing makes the customer feel smart.”

0 Comment

Leave a Comment

Your email address will not be published.

Do NOT follow this link or you will be banned from the site!