2

I have created custom tab and added template for this tab using this link.

  1. app/code/Namespace/Modulename/view/adminhtml/ui_component/product_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="demotab">
       <argument name="data" xsi:type="array">
           <item name="config" xsi:type="array">
               <item name="label" xsi:type="string" translate="true">Demo Tab</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_demo">
               <argument name="block" xsi:type="object">Namespace\Modulename\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo</argument>
           </htmlContent>
       </container>
   </fieldset>
</form>
  1. app/code/Namespace/Modulename/Block/Adminhtml/Catalog/Product/Edit/Tab/Demo.php
<?php
namespace Namespace\Modulename\Block\Adminhtml\Catalog\Product\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;

class Demo extends \Magento\Framework\View\Element\Template
{
    /**
     * @var string
     */
    protected $_template = 'product/edit/demo.phtml';

    /**
     * Core registry
     *
     * @var Registry
     */
    protected $_coreRegistry = null;

    public function __construct(
        Context $context,
        Registry $registry,
        array $data = []
    )
    {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Retrieve product
     *
     * @return \Magento\Catalog\Model\Product
     */
    public function getProduct()
    {
        return $this->_coreRegistry->registry('current_product');
    }

}
  1. app/code/Namespace/Modulename/view/adminhtml/templates/product/edit/demo.phtml
<?php echo "This is demo tab content."; ?>

But, The template values does not post in product form save action.

How to solve this...

Thanks.

1 Answer 1

2

Use below code in phtml file:

<p id="CustomTab" data-form-part="product_form" > 
    <?php echo "This is demo tab content."; ?> 
</p>
1
  • Hope it will be helpful!
    – ASQ
    Mar 1, 2019 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.