cancel
Showing results for 
Search instead for 
Did you mean: 

Custom ui_component data not being sent to controller

Custom ui_component data not being sent to controller

I've followed the Magento 2 dev docs (http://devdocs.magento.com/guides/v2.2/howdoi/customize_product.html) and created a custom ui_component to add an extra field to the product edit page, but when I click save the custom field values are not included in 

$this->getRequest()->getPostValue()

.

My code looks like this.

/etc/adminhtml/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">
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="customProductModifier" xsi:type="array">
                <item name="class" xsi:type="string">Vendor\Module\Ui\Modifier\Product\Form\CustomProductModifier</item>
                <item name="sortOrder" xsi:type="number">1</item>
            </item>
        </argument>
    </arguments>
</virtualType>

 

/ui_component/product_form.xml:

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="custom_products">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Label</item>
                <item name="sortOrder" xsi:type="number">1</item>
                <item name="collapsible" xsi:type="boolean">true</item>
            </item>
        </argument>
    <field name="custom_name" formElement="input">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="formElement" xsi:type="string">checkboxset</item>
                <item name="componentType" xsi:type="string">field</item>
                <item name="visible" xsi:type="number">1</item>
                <item name="sortOrder" xsi:type="number">1</item>
                <item name="label" xsi:type="string">Label</item>
            </item>
        </argument>
      </field>
   </fieldset>
</form>

CustomProductModifier.php:

<?phpnamespace Vendor\Module\Ui\Modifier\Product\Form;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Vendor\Module\Service\HTTPService;

class CustomProductModifier extends AbstractModifier{


public function modifyMeta(array $meta){    $meta['custom_products'] = [
        'children' => [
            'custom_name' => [
                'arguments' => [
                    'data' => [
                        'config' => [
                            'options' => $this->populateValues()
                        ]
                    ]
                ]
            ] 
        ]
    ];

    return $meta;
}

public function modifyData(array $data){
    return $data;
}

private function populateValues(){    $values = array(        array('value' => 'disabled', 'label' => 'Disabled'),
    );

    foreach(HTTPService::get_instance()->get_data() as $index => $data){        $values[] = array('value' => '$data['title'], 'label' => $data['title']);
    }

    return $values;
}

}

The tutorial ends here but there must be something missing.