8

I have created custom customer attribute successfully. Which are showing under account information tab of customer edit in admin.

I want to show them in my custom tab.

4
  • found the solution for this? Mar 29, 2018 at 2:52
  • Any body know solution ? Jul 31, 2018 at 5:55
  • I need a solution, too. Sep 28, 2018 at 13:07
  • the attributes under the account information tab are rendered generically based on a setting you can add to the customer attribute (include in forms, it's an own mapping table). If you have a custom tab, you have to render it yourself, but the "how" depends on how you implemented the custom tab Jan 11, 2019 at 21:12

1 Answer 1

0

To create a new tab in the admin customer edit, create a xml in the following path

Step 1:

/app/code/Vendorname/modulename/view/adminhtml/layout/customer_index_edit.xml

<body>
       <referenceBlock name="customer_form">
         <block class="Vendorname\Modulename\Block\Adminhtml\Edit\Tab\Test" name="customer_edit_tab_test" >
          <action method="setTabLabel">
              <argument name="label" xsi:type="string">Test Tab</argument>
          </action>
        </block>
      </referenceBlock>
</body>

Step 2: Create a block file in the below path to load the contents when the tab is clicked

/app/code/Vendorname/Modulename/Block/Adminhtml/Edit/Tab/Test.php

<?php

namespace Vendorname\Modulename\Block\Adminhtml\Edit\Tab;

use Magento\Customer\Controller\RegistryConstants;

use Magento\Ui\Component\Layout\Tabs\TabInterface;

class Test extends \Magento\Framework\View\Element\Template implements TabInterface
{

    protected $_coreRegistry;

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

    /**
     * @return string|null
     */
    public function getCustomerId()
    {
        return $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
    }
    /**
     * @return \Magento\Framework\Phrase
     */
    public function getTabLabel()
    {
        return __(‘Tab label’);
    }
    /**
     * @return \Magento\Framework\Phrase
     */
    public function getTabTitle()
    {
        return __(‘Tab Title’);
    }
    /**
     * @return bool
     */
    public function canShowTab()
    {
        if ($this->getCustomerId()) {
            return true;
        }
        return false;
    }

    /**
     * @return bool
     */
    public function isHidden()
    {
        if ($this->getCustomerId()) {
            return false;
        }
        return true;
    }
    /**
     * Tab class getter
     *
     * @return string
     */
    public function getTabClass()
    {
        return '';
    }
    /**
     * Return URL link to Tab content
     *
     * @return string
     */
    public function getTabUrl()
    {
    //replace the tab with the url you want
        return $this->getUrl('test/*/test', ['_current' => true]);
    }
    /**
     * Tab should be loaded trough Ajax call
     *
     * @return bool
     */
    public function isAjaxLoaded()
    {
        return true;
    }
}

Your new test tab will be added to customer edit left side menu.

1
  • how to write this url ? i have controller name Index.php and adminhrml route name hello
    – Ali Raza
    Sep 7, 2020 at 8:05

Your Answer

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

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