1

The product form page seems to disappear if I enable my custom catalog_product_new.xml.

See screenshot: enter image description here

I checked the log files and I see a main.CRITICAL: Block product_tabs throws exception and cannot be rendered. I can't seem to point out was is the culprit although I am assuming the issue is in the catalog_product_new.xml.

This is the code I have added:

Rahaha\AdminSample\view\adminhtml\layout\catalog_product_new.xml

<?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_tabs">
            <block class="Rahaha\AdminSample\Block\Adminhtml\Product\Edit\Tab\CustomTabz" name="custom-tab" template="product/tab/customtabz.phtml">
            </block>
            <action method="addTab">
                <argument name="name" xsi:type="string">product-reviews</argument>
                <argument name="block" xsi:type="string">custom-tab</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Rahaha\AdminSample\view\adminhtml\templates\catalog\product\tab\customtabz.phtml

<fieldset class="fieldset form-inline">
<legend class="legend"><span><?php echo __('Custom Tab') ?></span></legend>
<br>
<div id="table_cataloginventory">
<div class="field">
   <label class="label" for="custom_first">
        <span><?php  echo __('First') ?></span>
    </label>
    <div class="control">
        <input type="text" class="input-text" id="custom_first" name="first" value="first">
    </div>

</div>
<div class="field">
   <label class="label" for="custom_second">
        <span><?php  echo __('Second') ?></span>
    </label>
    <div class="control">
        <input type="text" class="input-text" id="custom_second" name="second" value="second">
    </div>

</div>

</div>
</fieldset>

Rahaha\AdminSample\Block\Adminhtml\Product\Edit\Tab\CustomTabz.php

<?php
namespace Rahaha\AdminSample\Block\Adminhtml\Product\Edit\Tab;

class CustomTabz extends \Magento\Backend\Block\Widget
{
    protected $_template = 'catalog/product/tab/customtabz.phtml';

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        array $data = []
    ) {
       parent::__construct($context, $data);
    }
}
1

Ok the tab finally is working now. Changes I have made to make it work:

Update the XML config catalog_product_new.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
    <body>
        <referenceBlock name="product_tabs">
            <block class="Rahaha\AdminSample\Block\Adminhtml\Product\Edit\Tab\RahahaProductTab" name="rahaha-tab" template="Rahaha_AdminSample::catalog/product/tab/rahahaproducttab.phtml" group="basic" />
            <action method="addTab">
                <argument name="label" xsi:type="string" translate="true">product_tabs.rahahaproducttab</argument>
                <argument name="block" xsi:type="string">rahaha-tab</argument>
            </action>
        </referenceBlock>
    </body>
</page>

implement TabInterface in CustomTab

class RahahaProductTab extends \Magento\Backend\Block\Widget implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
    public function canShowTab() {
        return true;
    }

    public function getTabLabel() {
        return _("Rahaha Integration");
    }

    public function getTabTitle() {
        return $this->getTabLabel();
    }

    public function isHidden() {
        return false;
    }

note: i renamed the class for personal reason, not part of solution.

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.