34

I'm trying to change the behaviour 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()-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?
  • 1
    That's the only way so far to customise kind of Ui component like this. The PHP modifiers. – Toan Nguyen Jul 18 '17 at 4:24
  • 2
    @Giel Berkers Your question is good but unfortunately I don't know how to answer it. Fortunately I have enough reputations to place bounty on your question to attract someone who knows to answer your question. My kind. – Farewell Stack Exchange Sep 4 '17 at 22:34
0

You can set <sequence> in module.xml of CatalogInventory module. After that, you can create product_form.xml under

app/code/Your/Module/view/adminhtml/ui_component/product_form.xml

With the same path as it is in the CatalogInventory. This will replace the configuration you needed.

I would like to provide any examples but I don't know what you need here. P.S. you don't need to add other elements you don't need in your XML. they will be taken from parent xml configuration.

0

there is a two way 1) create a new model(through new module creation in local pool) 2) to override the existing model of specific module which you want

-3
  1. Create a directory app/code/Vendor/Module
  2. Create a registration file app/code/Vendor/Module/registration.php with the following content:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
);
?>
  1. Create a composer file (if you plan to transfer the module) app/code/Vendor/Module/composer.json :
{
    "name": "vendor/module-module",
    "description": "N/A",
    "require": {
        "php": "~5.6.0|~7.0.0"
    },
    "type": "magento2-module",
    "version": "2.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Vendor\\Module\\": ""
        }
    }
}
  1. Now, create the module’s main XML-file app/code/Vendor/Module/etc/module.xml with the dependency from the Magento_Catalog module because our modal window will be added to its form:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="2.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>
  • 3
    Mind explaining how is your answer related to the question? – Vivek Kumar Mar 7 '18 at 11:09

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.