Magento – How to change an existing modal in Magento 2

magento2modal

I'm trying to change the behavior of a Modal (not Model) in Magento 2.
The modal in question is advanced_inventory_modal, declared in module-catalog-inventory/view/adminhtml/ui_component/product_form.xml.

Now I know I can use a Modifier in the product-form-modifier-pool:

<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="hf_quantity" xsi:type="array">
                <item name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\Product\Form\Modifier\Quantity</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
    </arguments>
</virtualType>

… and use the modifyMeta()-method in my modifier to manipulate the XML configuration, but for some reason, the inventory modal is not present in the data that is provided here. It's also not a sortOrder-related problem since I already set that way high. The sortOrder-attribute might have something to do with it.

So what gives? Can anyone tell me what's the proper way to modify the content of an existing modal in Magento 2?

Edit:

I found a solution or workaround (not sure yet) on how to achieve what I am trying to achieve. It turns out that if I set sortOrder to 10000 I have some data in my modifyMeta()-a method that I can use:

public function modifyMeta(array $meta)
{
    if ($path = $this->arrayManager->findPath('quantity_and_stock_status_qty', $meta, null, 'children')) {
        $this->arrayManager->remove(
            $path . '/children/qty/arguments/data/config/validation/validate-digits',
            $meta
        );
    }

    if ($path = $this->arrayManager->findPath('advanced_inventory_modal', $meta)) {
        $meta = $this->arrayManager->merge(
            $path . '/children/stock_data/children/qty/arguments/data/config',
            $meta,
            ['validation' => ['validate-digits' => false]]
        );
    }

    return $meta;
}

Note that the `advanced_inventory_modal` node is not yet complete, but my best guess is that the later addition of the modal merges with these settings, but doesn't override it. Could be wrong though, perhaps someone could share some more light on how this mechanism works?

Best Answer

There are two ways:
1. Create a new model(through new module creation in the local pool)
2. To override the existing model of the specific module which you want.