1

I try to add a new tab on Admin user edit

Admin edit page magento 2

I use this code,

adminhtml_user_edit.xml

<?xml version="1.0" encoding="utf-8" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="Test_adminhtml_user">
            <action method="addTab">
                <argument name="name" xsi:type="string">custom_tabs</argument>
                <argument name="block" xsi:type="string">Testing\test\Block\Adminhtml\User\Tab\Test</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Test.php

<?php

namespace Testing\test\Block\Adminhtml\User\Tab;

/**
 * Order custom tab
 *
 */
class Test extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
    protected $_template = 'tab/view/test.phtml';

    /**
     * View constructor.
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Retrieve order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrder()
    {
        return $this->_coreRegistry->registry('permissions_user');
    }
    /**
     * Retrieve order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrderId()
    {
        return $this->getOrder()->getEntityId();
    }

    /**
     * Retrieve order increment id
     *
     * @return string
     */
    public function getOrderIncrementId()
    {
        return $this->getOrder()->getIncrementId();
    }
    /**
     * {@inheritdoc}
     */
    public function getTabLabel()
    {
        return __('My Custom Tab');
    }

    /**
     * {@inheritdoc}
     */
    public function getTabTitle()
    {
        return __('My Custom Tab');
    }

    /**
     * {@inheritdoc}
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function isHidden()
    {
        return false;
    }
}

?>

test.phtml

<div class="fieldset-wrapper order-information">
    <div class="fieldset-wrapper-title">
        <span class="title"><?php /* @escapeNotVerified */
            echo __('Information for new Order tab') ?></span>
    </div>
    <table class="admin__table-secondary">
        <tbody>
        <?php echo $block->getChildHtml(); ?>
        <tr>
            <th><?php /* @escapeNotVerified */
                echo __('Order ID:') ?></th>
            <td><?php echo $block->getOrderIncrementId(); ?></td>
        </tr>
        <tr>
            <th><?php /* @escapeNotVerified */
                echo __('Last History:') ?></th>
            <td><?php echo __('History of order') ?></td>
        </tr>
        </tbody>
    </table>
</div>

but it's not displaying on admin user edit page, is there any solution ?

1 Answer 1

1

Modify layout by following code:

app/code/SR/MagentoCommunity/view/adminhtml/layout/adminhtml_user_edit.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="adminhtml.user.edit.tabs">
            <action method="addTab">
                <argument name="name" xsi:type="string">custom_tabs</argument>
                <argument name="block" xsi:type="string">SR\MagentoCommunity\Block\Adminhtml\User\Tab\Test</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Clear cache.

Note: Make sure your module name start with an uppercase character

[Update]

Add the following method in your block class which will sorting your tab [Testing/test/Block/Adminhtml/User/Tab/Test.php]

public function getAfter()
{
    return 'roles_section';
}
3
  • It's work perfectly sir, is there any method to add it after "User Role" ?
    – sayou
    May 6, 2019 at 15:56
  • 1
    Check updated answer
    – Sohel Rana
    May 6, 2019 at 16:05
  • Perfect sir, thanks a lot
    – sayou
    May 6, 2019 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.