1

I just want to rewrite modifyMeta method on vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/Related.php file and I have done following things in file but not succeeded.

I have followed the Magento 2: How to override Ui & Component folder files answer, but unable to rewrite the method.

Here steps what I did:

  1. app/code/Custom/Modulename/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related" type="Custom\Modulename\Ui\DataProvider\Product\Form\Modifier\Related"/>
</config>
  1. app/code/Custom/Modulename/Ui/DataProvider/Product/Form/Modifier/Related.php
<?php

namespace Custom\Modulename\Ui\DataProvider\Product\Form\Modifier;

use Magento\Ui\Component\Form\Fieldset;

class Related extends \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related
{
    
    public function modifyMeta(array $meta)
    { 
       echo "In overrided class " , get_class($this);
       die;
    }
}

Note: I am using Magento 2 Enterprise Editions 2.1.7

Any help would be appreciated.

3
  • Did you give a try using a plugin as you are trying to override a public function instead of using a preference?
    – Nikolas
    Commented Aug 4, 2017 at 12:13
  • No. Let me try with that. Commented Aug 5, 2017 at 13:11
  • @Nikolas : did not work. Commented Aug 8, 2017 at 12:34

1 Answer 1

5

I have overridden modifyMeta method by using virtualType tag in adminhtml/di.xml

<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="logotype" xsi:type="array">
                <item name="class" xsi:type="string">Custom\Modulename\Ui\DataProvider\Product\Form\Modifier\Related</item>
                <item name="sortOrder" xsi:type="number">130</item>
            </item>
        </argument>
    </arguments>
</virtualType>
1

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.