5

If I have something like this:

<type name="Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Composite">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="downloadablePanel" xsi:type="string">Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\DownloadablePanel</item>
            <item name="links" xsi:type="string">Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Links</item>
            <item name="samples" xsi:type="string">Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Samples</item>
            <item name="usedDefault" xsi:type="string">Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\UsedDefault</item>
        </argument>
    </arguments>
</type>

and I want to change one of these classes in <item> nodes. Is it possible via di.xml?

I have used <preference> and it worked, but I don't feel as it is best solution. Of course for public methods plugin should work. What in case of protected or private method?

6

Let's say you want to change the links one.
You have to create your own module that depends on the Magento_Downloadable module and add this in the di.xml of your module.

<type name="Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Composite">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="links" xsi:type="string">Your\ClassName\Goes\Here</item>
        </argument>
    </arguments>
</type>

Just keep in mind that if the code you posted is from frontend/di.xml you have to add the new code in frontend/di.xml. Same goes for adminhtml/di.xml

  • If plugin is possible for such a class I bet it's better to use plugin over changing item class via xml, isn't it? – Bartosz Kubicki Jan 9 '17 at 8:15
  • yes, you can do that, but from the question I understood that you want to completely replace one of the items. – Marius Jan 9 '17 at 8:18
  • actually I want to override method which is protected so we can exclude for this case plugins. Comment just in sake of complecity if somone would read it and find it helpful :) – Bartosz Kubicki Jan 9 '17 at 8:25
  • What in case virtualType? For example: <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool"> <arguments> <argument name="modifiers" xsi:type="array"> <item name="downloadable" xsi:type="array"> <item name="class" xsi:type="string">Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Composite</item> <item name="sortOrder" xsi:type="number">20</item> </item> </argument> </arguments> </virtualType> – Bartosz Kubicki Jan 9 '17 at 8:46
  • 2
    @lord_of_strings, you dont need to override protected methods in Links class. You need to modify product form component data or metadata. There is nice functionality of Magento\Ui\DataProvider\Modifier\Pool, integrated to product form component. I think, that you need to use custom modifier after Downloadable modifier and rewrite needed data in array. – Max Jan 9 '17 at 9:17

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.