Wishusucess AdminMenu: How to Create Magento 2 Admin Menu Module

Here you will see how we can create Magento 2 Wishusucess AdminMenu Module, and also you will get to know how to add a link to the Magento 2 Admin Menu, which is shown on the left side of the Admin Menu pages of Magento 2.

 

Structure of the Magento 2 Admin Menu

How Magento 2 menu item performs an action on each menu item.

Here we have created a menu which is Wishusucess and that has a two-item level menu which is Admin Menu One and the second menu item which is Admin Menu Two.

Wishusucess AdminMenu
Wishusucess AdminMenu Item

 

Folder Structure of Wishusucess AdminMenu

Magento_2_Root_Direcotry/app/code/

Wishusucess/AdminMenu/registration.php

Wishusucess/AdminMenu/etc/module.xml

Wishusucess/AdminMenu/etc/adminhtml/menu.xml

So you need only three files to create an Admin Menu item.

Now let's see how that file we have to write.

 

Step 1: Register Your Magento 2 Module

First, we have to register our module through the following file.

Wishusucess/AdminMenu/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_AdminMenu',
__DIR__
);

 

Step 2: Give the Basic Information of Module

Wishusucess/AdminMenu/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_AdminMenu" setup_version="1.0.0">
</module>
</config>

 

Step 3: Create Magento 2 AdminMenu Item

Wishusucess/AdminMenu/etc/adminhtml/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="Wishusucess_AdminMenu::adminmenu" title="Wishusucess" module="Wishusucess_AdminMenu" sortOrder="51" resource="Wishusucess_AdminMenu::adminmenu"/>
<add id="Wishusucess_AdminMenu::one" title="Admin Menu One" module="Wishusucess_AdminMenu" sortOrder="10" action="wishusucess_adminmenu/one" resource="Wishusucess_AdminMenu::one" parent="Wishusucess_AdminMenu::adminmenu"/>
<add id="Wishusucess_AdminMenu::two" title="Admin Menu Two" module="Wishusucess_AdminMenu" sortOrder="99" parent="Wishusucess_AdminMenu::adminmenu" action="adminhtml/system_config/edit/section/adminmenu" resource="Wishusucess_AdminMenu::adminmenu_configuration"/>
</menu>
</config>

 

Now Run The Following Command to See Wishusucess AdminMenu:

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deplpy -f

php bin/magento cache:clean

 

Magento 2 AdminMenu Attribute Definitions

Now the basic attribute which we need to understand.

The id: Identifier or It’s a unique string

format: {Vendor_ModuleName}::{menu_description}.

The title: Text which will be shown on the menu bar.

The module: Menu is belong to.

The sortOrder: Defined the position of the menu.

Priority Order: 0 Means top priority

  • 10: Highest Priority
  • 20: Second Highest
  • 30: Third Highest
  • and so on...

The parent: This decides which is the parent of other items.

For example, we have parent=”Wishusucess_AdminMenu::adminmenu”, so we - know this menu “Admin Menu One” is a child of “Wishusucess” menu and it will show inside of Wishusucess menu.

The action: Define the URL of the page to which this menu links.

format: {router_name}{controller_folder}{action_name}.

In this example, this menu will link to the module Wishusucess, controller one, and action Index

The resource: Defined the Access Control Language (ACL) rule which the admin user must have in order to see and access this menu.

 

AdminMenu Module Download Link:

AdminMenu GitHub

Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Related Post:

HelloWorld Extension: How to Create Hello World Module

 

Leave a Reply