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"/>
  1. app/code/Custom/Modulename/Ui/DataProvider/Product/Form/Modifier/Related.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);

Note: I am using Magento 2 Enterprise Editions 2.1.7

Any help would be appreciated.

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

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

<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
        <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>

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.