I tried to create a new tab in customer edit backend.
First i create the
app/code/Namespace/Point/view/adminhtml/layout/customer_index_edit.xml
<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="customer_form">
<block class="Namespace\Point\Block\Adminhtml\Edit\Tab\CustomerPoint" name="customer_edit_tab_customerpoint" >
<action method="setTabLabel">
<argument name="label" xsi:type="string">Namespace Point</argument>
</action>
</block>
</referenceBlock>
</body>
</page>
then i create the block:
app/code/Namespace/Point/Block/Adminhtml/Edit/Tab/CustomerPoint.php
namespace Namespace\Point\Block\Adminhtml\Edit\Tab;
use Magento\Customer\Controller\RegistryConstants;
use Magento\Ui\Component\Layout\Tabs\TabInterface;
class CustomerPoint 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);
}
public function getCustomerId()
{
return $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
}
public function getTabLabel()
{
return __("Namespace Point");
}
public function getTabTitle()
{
return __('Namespace Point');
}
public function canShowTab()
{
if ($this->getCustomerId()) {
return true;
}
return false;
}
public function isHidden()
{
if ($this->getCustomerId()) {
return false;
}
return true;
}
public function getTabClass()
{
return '';
}
public function getTabUrl()
{
return $this->getUrl('namespace_point/customerpoint/tab', ['customer_id'=>$this->getCustomerId(),'_current' => true]);
}
public function isAjaxLoaded()
{
return true;
}
}
at this point the tab is showing in customer edit admin. Then i create the route app/code/Namespace/Point/etc/adminhtml/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route frontName="namespace_point" id="namespace_point">
<module before="Magento_Backend" name="Namespace_Point"/>
</route>
</router>
</config>
then the controller app/code/Namespace/Point/Controller/Adminhtml/Customerpoint/Tab.php
namespace Namespace\Point\Controller\Adminhtml\CustomerPoint;
class Tab extends \Magento\Customer\Controller\Adminhtml\Index
{
public function execute()
{
$this->initCurrentCustomer();
$resultLayout = $this->resultLayoutFactory->create();
return $resultLayout;
}
}
then i create layout for this controller layout
app/code/Namespace/Point/view/adminhtml/layout/namespace_point_customerpoint_tab.xml
<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<container name="root" label="Root">
<block class="Namespace\Point\Block\Adminhtml\Edit\Tab\CustomerPoint" name="point.edit.tab.customerpoint" template="Namespace_Point::customer_point_tab.phtml" cacheable="false"/>
</container>
</layout>
and finally the templates file app/code/Namespace/Point/view/adminhtml/templates/customer_point_tab.phtml
<h1> POINT </h1>
but when i click the new customer tab, it gives me blank page, when i use the tab url in my browser, it gives me blank page too, when i add die('test');
at the controller it prints test
but when i add die('test');
in the block constructor it gives blank page, seems like the controller doesn't read the xml layout file to generate
Best Answer
please correct this:
your layout should be like this: