0

I want to add new tab in product edit page using controller_action_layout_render_before_adminhtml_catalog_product_edit event. Can anyone help.

1 Answer 1

1

In 2.1+ product edit page is built using UI Components and PHP modifiers. Not sure you can modify it using mentioned event. Even if you could it's incorrect.

Hope you are familiar with UI Components. If not, these pages can help you to start: UI Components Overview, UI Components Modifiers.

Product Edit Page base configuration file

app/code/Magento/Catalog/view/adminhtml/ui_component/product_form.xml

defines root modifier

Magento\Catalog\Ui\DataProvider\Product\Form\ProductDataProvider

Looking into you can find that it is just iterates through number of more specific modifiers. Complete list you can find in

app/code/Magento/Catalog/etc/adminhtml/di.xml

under node

<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool">

node.

Take a look into modifier for websites

<item name="websites" xsi:type="array">
    <item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Websites</item>
    <item name="sortOrder" xsi:type="number">30</item>
</item>

it is most relevant to your case. It defines new collapsible section(tab) Websites In your case you need create new modifier and configure it.

Hope this will help you to understand product edit form in Magento 2 (2.1+) a bit

UPDATE

Here is my files:

Yaronish\Catalog\etc\adminhtml\di.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<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="test" xsi:type="array">
                    <item name="class" xsi:type="string">Yaronish\Catalog\Ui\DataProvider\Product\Form\Modifier\Test</item>
                    <item name="sortOrder" xsi:type="number">15</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
</config>

app/code/Yaronish/Catalog/Ui/DataProvider/Product/Form/Modifier/Test.php

<?php
namespace Yaronish\Catalog\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Ui\Component\Form;

class Test extends AbstractModifier
{
    /**
     * {@inheritdoc}
     */
    public function modifyData(array $data)
    {
        return $data;
    }

    /**
     * {@inheritdoc}
     */
    public function modifyMeta(array $meta)
    {
        $meta = array_replace_recursive(
            $meta,
            [
                'test' => [
                    'arguments' => [
                        'data' => [
                            'config' => [
                                'additionalClasses' => 'admin__fieldset-product-test',
                                'label' => __('Test Section'),
                                'collapsible' => true,
                                'componentType' => Form\Fieldset::NAME,
                                'dataScope' => self::DATA_SCOPE_PRODUCT,
                                'disabled' => false,
                                'sortOrder' => $this->getNextGroupSortOrder(
                                    $meta,
                                    'search-engine-optimization',
                                    15
                                )
                            ],
                        ],
                    ],
                    'children' => [],
                ],
            ]
        );

        return $meta;
    }
}

Result:

Test Section Screenshot

1
  • Not so far. I am still stuck on this.
    – Pradip
    Commented Jan 18, 2017 at 13:34

Your Answer

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

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