0

This is my ui component file content:

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">vendor_modulename_shippingmethods_form.shippingmethods_form_data_source</item>
        </item>
        <item name="label" translate="true" xsi:type="string">General Information</item>
        <item name="template" xsi:type="string">templates/form/collapsible</item>
    </argument>
    <dataSource name="shippingmethods_form_data_source">
        <dataProvider class="Vendor\Modulename\Model\ShippingMethods\DataProvider" name="shippingmethods_form_data_source">
            <settings>
                <requestFieldName>entity_id</requestFieldName>
                <primaryFieldName>entity_id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <fieldset name="general">
        <settings>
            <label translate="true">Shipping Method Infomation</label>
        </settings>
        <field formElement="input" name="name" sortOrder="20">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="source" xsi:type="string">name</item>
                    <item name="label" xsi:type="string" translate="true">Name</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="dataScope" xsi:type="string">name</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">false</rule>
                </validation>
            </settings>
        </field>
    </fieldset>
</form>

and this is my DataProvider:

    namespace Vendor\ModuleName\Model\ShippingMethods;

    use Vendor\ModuleName\Model\ResourceModel\ShippingMethods\CollectionFactory;

    class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
    {

        protected $_loadedData;

        public function __construct(
            $name,
            $primaryFieldName,
            $requestFieldName,
            CollectionFactory $employeeCollectionFactory,
            array $meta = [],
            array $data = []
        ) {
            $this->collection = $employeeCollectionFactory->create();
            parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
        }

        public function getData()
        {
            if (isset($this->_loadedData)) {
                return $this->_loadedData;
            }
            $items = $this->collection->getItems();
            .......
        }
    }

If I display my query string in the getData() with echo $this->collection->getSelect();, the result is:

SELECT `main_table`.* FROM `mytable` AS `main_table` WHERE (`entity_id` = '') . My id is missing. Not sure how, any idea where to look ?  Thnx in advance
1

They were empty because the primaryFieldName and requestFieldName had wrong values. Instead of entity_id in my case i need to change it to simply id.

| improve this answer | |

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.