0

I am a beginner in Magento (version 2.3).

I am looking for a solution to create a form with custom attributes, which would be displayed by clicking on a custom tab in Customer admin.

I have understood how to create a custom attribute and have seen how to create a new tab.

The problem I encounter is how to join these two?

I saw my attribute can be used_in_forms. Should I create a new form here? In this case, how to create and render the form?

Thank you for your help,

Jeremy

22
  • you want to make a custom tab in customer edit section right? in admin side Jan 14, 2019 at 8:31
  • @AdarshShukla yes exactly
    – jargoud
    Jan 14, 2019 at 10:39
  • ok wait i will answer you in am moment Jan 14, 2019 at 11:01
  • check answer if any issue comment Jan 14, 2019 at 11:23
  • Thanks! There is still one thing I cannot understand, it is how to do to render eav attributes in this form. Does it need to be done manually in the phtml template? How is it achieved by Magento when I add an eav attribute in the customer_account_edit form?
    – jargoud
    Jan 14, 2019 at 13:03

1 Answer 1

-1

Step 1:Create app/code/Vendor/Module/view/adminhtml/layout/customer_index_edit.xml File

with block decleration

Step 2:Create app/code/Vendor/Module/Block/Adminhtml/View.php File content of View.php

class View extends \Magento\Backend\Block\Template implements \Magento\Ui\Component\Layout\Tabs\TabInterface { /** * Template * * @var string */ protected $_template = 'tab/customer_view.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);
}

/**
 * @return string|null
 */
public function getCustomerId()
{
    return $this->_coreRegistry->registry(\Magento\Customer\Controller\RegistryConstants::CURRENT_CUSTOMER_ID);
}

/**
 * @return \Magento\Framework\Phrase
 */
public function getTabLabel()
{
    return __('Custom Tab');
}

/**
 * @return \Magento\Framework\Phrase
 */
public function getTabTitle()
{
    return __('Custom Tab');
}

/**
 * @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()
{
    return '';
}

/**
 * Tab should be loaded trough Ajax call
 *
 * @return bool
 */
public function isAjaxLoaded()
{
    return false;
}

}

step 3:create app/code/Vendor/Module/view/adminhtml/templates/tab/customer_view.phtml with Your desin logic and if you want to pass some data use block file code

get referance from here

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.