I am trying to display a grid for my module on an extra tab added on the customer_index_edit. I managed to add custom tab, and i am trying to add layout, like in Magento_Wishlist, but it`s unsuccessfully. When i click the tab, nothing changed.
Can someone help me?
UPDATE:
I created layout {Vendor}/{Extension}/view/adminhtml/layout/customer_index_edit.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_form">
<block class="Webinse\Crm\Block\Adminhtml\CustomerReminderTab" name="crm_reminders">
</block>
</referenceBlock>
</body>
</page>
Next, i created Block {Vendor}/{Extension}/Block/Adminhtml/CustomerReminderTab.php
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Webinse\Crm\Block\Adminhtml;
use Magento\Framework\Registry;
use Magento\Backend\Block\Template\Context;
use Magento\Ui\Component\Layout\Tabs\TabWrapper;
use Magento\Ui\Component\Layout\Tabs\TabInterface;
use Magento\Customer\Controller\RegistryConstants;
class CustomerReminderTab extends TabWrapper implements TabInterface
{
/**
* Core registry
*
* @var Registry
*/
protected $coreRegistry = null;
/**
* @var bool
*/
protected $isAjaxLoaded = true;
/**
* Constructor
*
* @param Context $context
* @param Registry $registry
* @param array $data
*/
public function __construct(Context $context, Registry $registry, array $data = [])
{
$this->coreRegistry = $registry;
parent::__construct($context, $data);
}
/**
* @inheritdoc
*/
public function canShowTab()
{
return $this->coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
}
/**
* Return Tab label
*
* @return \Magento\Framework\Phrase
*/
public function getTabLabel()
{
return __('CRM');
}
/**
* Return URL link to Tab content
*
* @return string
*/
public function getTabUrl()
{
return $this->getUrl('customer/*/reminder', ['_current' => true]);
}
}
Next {Vendor}/{Extension}/view/adminhtml/layout/customer_index_reminder.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd">
<container name="root">
<block class="Magento\Framework\View\Element\Template" as="grid">
<arguments>
<argument name="template" xsi:type="string">Webinse_Crm::customer/edit/tab/reminder.phtml</argument>
</arguments>
</block>
</container>
</layout>
And template {Vendor}/{Extension}/view/adminhtml/templates/customer/edit/tab/reminder.phtml
<?php echo 'hello world'; ?>
But it`s not working. When i click on the tab, i have nothing.
Can someone explain how to do this in the right way?
Best Answer
Please follow below steps
admin layout xml app\code\Sugarcode\Test\view\adminhtml\layout\test_lists_edit.xml
controller where you need to check id is there or not to fill form and save the data in register
app\code\Sugarcode\Test\Controller\Adminhtml\Lists\Edit.php
lets move on to block app\code\Sugarcode\Test\Block\Adminhtml\Lists\Edit.php
as like in magneto1.x here alo we have mode which default folder name is edit so create folder called edit then create below files
app\code\Sugarcode\Test\Block\Adminhtml\Lists\Edit\Form.php
app\code\Sugarcode\Test\Block\Adminhtml\Lists\Edit\tabs.php
now create folder called form and file main.php as per layout xml this will load in form container if you need tabs then you need to use interface
then interface function needs to be implemented here in below code below Prepare label for tab are for tabs app\code\Sugarcode\Test\Block\Adminhtml\Lists\Edit\Tab\Main.php
if you dont wants tabs then follow below code
app\code\Sugarcode\Test\view\adminhtml\layout\test_lists_details.xml
app\code\Sugarcode\Test\Controller\Adminhtml\Lists\Details.php
now in blocks app\code\Sugarcode\Test\Block\Adminhtml\Lists\Details.php
in above file imp code is
$this->_mode = 'details';
and finally app\code\Sugarcode\Test\Block\Adminhtml\Lists\Details\Form.php
above are the two ways of edit for ,
edit is for edit a content with tab and
details is for edit a content without tabs