3

I want to add new tab in product edit page and for that i have follow this steps :

  1. 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>
    
  2. Now I want to call custom phtml file to render html. How can I call custom phtml file ?

4

2 Answers 2

5

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

2
  • i have to create custom tab in edit grid and also open pop-up of grid but i have open my custom grid open in this grid so any one can solution? I have Follow this link "github.com/meetvora1021/Product-Edit-Tab/tree/master/app/code/…" for solution and create filed and also open pop-up.
    – meet
    Jul 11, 2017 at 10:44
  • how to disable tab on specific conditions? I have tried return false on canshowtab() method. It's not working Jun 17, 2020 at 5:09
0

I Found One Solution So Please Check it this link "https://github.com/meetvora1021/Product-Edit-Tab/tree/master/app/code/Meet/Productgridextend"

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.