How to Add a New Tab in User Editing Page in Magento 2

Here the following steps explain you how to add a new tab in user editing page in Magento 2:

Step 1: Form the file \app\code\Webnexs\InventorySuccess\

etc\adminhtml\events.xml

Step 2: Form the file \app\code\Webnexs\InventorySuccess\Observer\

Permission\Warehouse\ViewBlockAbstractToHtmlBefore.php

In this article, we will try to add a new tab in to user editing page in Magento 2. We will use the event view_block_abstract_to_html_ before to do it:

Step 1:

We want to form a file:

\app\code\Webnexs\InventorySuccess\etc\adminhtml\events.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

   <event name="view_block_abstract_to_html_before">

       <observer name="staff_add_permission_view_block_abstract_to_html_before" instance="Webnexs\InventorySuccess\Observer\Permission\Staff\ViewBlockAbstractToHtmlBefore" />

   </event>

</config>

Step 2:

We will form a file:

\app\code\Webnexs\InventorySuccess\Observer\Permission\

Warehouse\ViewBlockAbstractToHtmlBefore.php to call the tab that you want to add:

<?php


namespace Webnexs\InventorySuccess\Observer\Permission\Staff

use Magento\Framework\Event\Observer as EventObserver;

use Magento\Framework\Event\ObserverInterface;

class ViewBlockAbstractToHtmlBefore implements ObserverInterface

{

   /**

    * @param EventObserver $observer

    * @return $this

    */

   public function execute(EventObserver $observer)

   {

       $block = $observer->getEvent()->getBlock();

       if($block instanceof \Magento\User\Block\User\Edit\Tabs){

           $block->addTab(

               'warehouse_section',

               [

                   'label' => __('Warehouse'),

                   'title' => __('Warehouse'),

                   'after' => __('roles_section'),

                   'content' => $block->getLayout()->createBlock(

                       'Webnexs\InventorySuccess\Block\Adminhtml\Permission\Edit\Tab\Warehouse\Selected',

                       'user.warehouse.grid'

                   )->toHtml()

               ]

           );

       }

       return $this;

   }

}

After that you will observe like:

insert a new tab

The above mentioned steps describe you how to add New Tab in User Editing Page in Magento 2

Last Update: April 7, 2018  

March 15, 2018   224   Nandini Ramachandran    Operations    
Total 0 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

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

Facebook
Twitter
INSTAGRAM
LinkedIn