7 Steps to Create a New Admin Menu in Magento 2 at ThaiLand

7 Steps to Create a New Admin Menu in Magento 2 at ThaiLand

Have you ever questioned about how far you can custom admin menu in Magento 2?

 Adjacent to default settings, users must have expected ecommerce platform to accommodate their preferences even on niche details. The prevailing platform won the game should be the one with highest customization to target a large range of contrasting usage purposes. Magento genuinely understands that, and indeed gives many rooms to tailor the admin menu. Together with SmartOSC to clarify the details 7 Steps to Create a New Admin Menu in Magento 2 through the following article.

Step 1: Register The Module. Create The File Registration.Php

Path:  app/code/Bss/CreateMenuBackend/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(

   \Magento\Framework\Component\ComponentRegistrar::MODULE,

   ‘Bss_CreateMenuBackend’,

   __DIR__

);

See more articles: https://www.smartosc.com/insights/top-10-magento-development-companies-in-singapore

Step 2: Configure Module. Create File Module.Xml

Path:  app/code/Bss/CreateMenuBackend/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=”Bss_CreateMenuBackend” setup_version=”1.0.0″>

   </module>

</config>

Step 3: Create File Menu.Xml

Path:  app/code/Bss/CreateMenuBackend/etc/adminhtml/menu.xml

– Below is a sample of main menu, set name as: “Bss Menu”.

<?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=”Bss_CreateMenuBackend::menu”

    title=”Bss Menu” module=”Bss_CreateMenuBackend”

    sortOrder=”10″

    resource=”Magento_Backend::content”

    />

   </menu>

</config>

See more articles: https://www.smartosc.com/insights/magento-development-service-company

Attributes:

  • Id: Specify identifier of the menu. It should be unique and comply with the format: [Namespace_ModuleName]::[menu_name].
  • Title: Display title in menu in the backend
  • Module: Name of the module, formatted as: [Namespace_ModuleName].
  • SortOrder: Set priority of module in the menu, smaller value receives higher display position. Module receives value “0” can be added with an icon.
  • Resource: Create ACL rule to set admin users who can see and access the created menu
Related Articles:   Magento 2 vs. Shopify: Which Should You Choose in Thailand

–  Enter following commands in root file of Magento:

1: php bin/magento module:enable Bss_DemoMenu

2: php bin/magento setup:upgrade

3: php bin/magento setup:static-content:deploy -f

4: php bin/magento cache:flush

It turns out a main menu Bss Menu at the left navigation – Admin Menu

7 Steps to Create a New Admin Menu in Magento 2 at Singapore

Successful created new admin menu

– Create a new sub-menu in the main menu. Set Bss Items as its name.

<?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=”Bss_CreateMenuBackend::menu”

    title=”Bss Menu” module=”Bss_CreateMenuBackend”

    sortOrder=”10″

    resource=”Magento_Backend::content”

    />

      

    <add id=”Bss_CreateMenuBackend::menu_item”

    title=”Bss Items” module=”Bss_CreateMenuBackend”

    sortOrder=”10″ parent=”Bss_CreateMenuBackend::menu”

    action=”createmenubackend/create/index”

    resource=”Bss_CreateMenuBackend::menu_item”

    />

   

   </menu>

</config>

Attributes in sub-menu:

  • Parent: Value is the ID of the main menu. It specifies the sub menu belongs to parentory menu.
  • Action: Direct URL if clicking to the menu, as format [router_name]/[controller_name]/[action_name]. – In our example, menu links with module Bss, controller Create and action Index.

Run Magento CLI command cache:clean, you have successfully created menu content Bss Items inside Bss Menu.

7 Steps to Create a New Admin Menu in Magento 2 at Singapore

See more articles: Magento Agency

Step 4: Create File Routes.Xml

Path:  app/code/Bss/CreateMenuBackend/etc/adminhtml/routes.xml

<?xml version=”1.0″?>

<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:App/etc/routes.xsd”>

<router id=”admin”>

<route id=”createmenubackend” frontName=”createmenubackend”>

<module name=”Bss_CreateMenuBackend”/>

</route>

</router>

</config>

Step 5: Create Page To Attach Link In The Menu. Create File Index.Php

Path:  app/code/Bss/CreateMenuBackend/Controller/Adminhtml/Create/Index.php

<?php

namespace Bss\CreateMenuBackend\Controller\Adminhtml\Create;

class Index extends \Magento\Backend\App\Action

{

      protected $resultPageFactory = false; 

      public function __construct(

              \Magento\Backend\App\Action\Context $context,

              \Magento\Framework\View\Result\PageFactory $resultPageFactory

      ) {

              parent::__construct($context);

              $this->resultPageFactory = $resultPageFactory;

      } 

      public function execute()

      {

              $resultPage = $this->resultPageFactory->create();

Related Articles:   Magento 2 Currency – Avail All The Best Details Now At ThaiLand

              $resultPage->setActiveMenu(‘Bss_CreateMenuBackend::menu’);

              $resultPage->getConfig()->getTitle()->prepend(__(‘Demo Menu’));

              return $resultPage;

      }

      protected function _isAllowed()

      {

              return $this->_authorization->isAllowed(‘Bss_CreateMenuBackend::menu’);

      }

}

Step 6: Determine The Interface Of The Page

Define layout and page structure. Create file createmenubackend_create_index

Path: app/code/Bss/CreateMenuBackend/view/adminhtml/layout/createmenubackend_create_index.xml

<?xml version=”1.0″?>

<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>

   <body>

       <referenceContainer name=”content”>

               <block class=”Magento\Backend\Block\Template” template=”Bss_CreateMenuBackend::helloworld.phtml”/>

       </referenceContainer>

   </body>

</page>

Set up page content. Create file helloworld.phtm

Path: app/code/Bss/CreateMenuBackend/view/adminhtml/templates/helloworld.phtml

<p>Hello World</p>

Step 7: Install Module

Run command in root file of Magento:

php bin/magento setup:upgrade

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

php bin/magento cache:flush

This is outcome when clicking to sub menu Bss Items:

7 Steps to Create a New Admin Menu in Magento 2 at Singapore

Article source: Magento Việt Nam

3 thoughts on “7 Steps to Create a New Admin Menu in Magento 2 at ThaiLand

  1. escape room says:

    hey there and thank you for your information – I’ve certainly picked
    up something new from right here. I did however expertise some
    technical points using this website, as I experienced to reload the site lots of times previous to I could get it to load properly.
    I had been wondering if your web host is OK? Not that I am complaining,
    but sluggish loading instances times will sometimes affect your placement
    in google and could damage your high-quality score if ads and marketing with Adwords.

    Well I’m adding this RSS to my e-mail and can look out for a
    lot more of your respective interesting content.
    Make sure you update this again very soon.. Escape roomy lista

Leave a Reply

Your email address will not be published. Required fields are marked *


Our Ecosystem : Vietnam, Australia 1, Singapore 1, Thailand, Australia 2, Singapore 2, USA 1, Australia 3, Singapore 3, USA 2, Singapore 4, Australia 4, Ecommerce, USA 3, Meeting Room Booking, Visitor Management system