Add new tab in product edit page in Magento 2.1
-
10-10-2020 - |
Question
I want to add new tab in product edit page and for that i have follow this steps :
Create di.xml and add below code:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool"> <arguments> <argument name="modifiers" xsi:type="array"> <item name="modulename" xsi:type="array"> <item name="class" xsi:type="string">Namespace\Modulename\Ui\DataProvider\Product\Modifier\Customtab</item> <item name="sortOrder" xsi:type="number">200</item> </item> </argument> </arguments> </virtualType> <type name="Namespace\Modulename\Ui\DataProvider\Product\Modifier\Customtab"> <arguments> <argument name="formName" xsi:type="string">product_form</argument> <argument name="dataScopeName" xsi:type="string">product_form.product_form</argument> <argument name="dataSourceName" xsi:type="string">product_form.product_form_data_source</argument> </arguments> </type> </config>
Now I want to call custom phtml file to render html. How can I call custom phtml file ?
Solution 2
I Found One Solution So Please Check it this link "https://github.com/meetvora1021/Product-Edit-Tab/tree/master/app/code/Meet/Productgridextend"
OTHER TIPS
Create product_form.xml file in app/code/VendorName/NameSpace/view/adminhtml/ui_component
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="fieldname">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">{{Tab name}}</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
</argument>
<container name="fieldname_container" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">160</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">VendorName\NameSpace\Block\Adminhtml\Catalog\Product\Tabs\Demo</argument>
</htmlContent>
</container>
</fieldset>
</form>
Create Demo.php in app/code/VendorName/NameSpace/Block/Adminhtml/Catalog/Product/Tabs
<?php
namespace VendorName\NameSpace\Block\Adminhtml\Catalog\Product\Tabs;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
class Demo extends Generic implements TabInterface
{
protected $_template = 'demo.phtml';
protected $_systemStore;
protected $_scopeConfig;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Store\Model\System\Store $systemStore,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
array $data = []
) {
$this->_systemStore = $systemStore;
$this->_scopeConfig = $scopeConfig;
parent::__construct($context, $registry, $formFactory, $data);
}
public function getTabLabel()
{
return __('Actions');
}
public function getTabTitle()
{
return __('Actions');
}
public function canShowTab()
{
return true;
}
public function isHidden()
{
return false;
}
public function getReqest()
{
return $this->getRequest()->getParams();
}
}
Create demo.phtml file in app/code/VendorName/NameSpace/view/adminhtml/templates
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange