Here we will learn how to add Tab on product edit page magento admin in Magento Version 2.1.0.
Magento 2.1.0 structure is different from previous version of magento2.
First create ‘catalog_product_edit.xml’ file in location Webkul/Demo/view/adminhtml/layout.
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="product_form"> <block class="Webkul\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo" name="demo.tab"> <arguments> <argument 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="opened" xsi:type="boolean">true</item> <item name="sortOrder" xsi:type="string">2</item> <item name="canShow" xsi:type="boolean">true</item> <item name="componentType" xsi:type="string">fieldset</item> </argument> </arguments> </block> </referenceBlock> </body> </page>
Now create block ‘Webkul\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo’.
Create Demo.php in location Webkul/Demo/Block/Adminhtml/Catalog/Product/Edit/Tab.
<?php namespace Webkul\Demo\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; /** * @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); } /** * Retrieve product * * @return \Magento\Catalog\Model\Product */ public function getProduct() { return $this->_coreRegistry->registry('current_product'); } }
protected $_template = ‘product/edit/demo.phtml’
This template file will be called in tab content.
Now create template file demo.phtml in location Webkul/Demo/view/adminhtml/templates/product/edit.
This is demo tab content.
If you are using Magento 2.0.x then read how to add tab on product page in Magento 2.0.x Admin.
If you have any query please comment below.