6

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.

  • found the solution for this? – CompactCode Mar 29 '18 at 2:52
  • Any body know solution ? – amit_game Jul 31 '18 at 5:55
  • I need a solution, too. – skymeissner Sep 28 '18 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 – David Verholen Jan 11 at 21:12
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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