Magento 2 image not uploading in edit form
- DataProvider of UI Component:
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Loyalty\PointsMall\Model\ResourceModel\Products\DataProvider</argument>
<argument name="name" xsi:type="string">loyalty_pointsMall_products_edit_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">earning_rule_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="submit_url" xsi:type="url" path="*/*/save"/>
</item>
</argument>
</argument>
- DataProvider.php
public function getData()
{
if($this->request->getParams('id')){
$collcetion = $this->productsFactory->create();
$collcetion->load($this->request->getParams('id'));
$this->_loadedData[$collcetion->getId()] = $collcetion->getData();
}
return $this->_loadedData;
}
- Change function getData() as follow:
public function getData()
{
if($this->request->getParams('id')){
$collcetion = $this->productsFactory->create();
$collcetion->load($this->request->getParams('id'));
$productData = $collcetion->getData();
if (isset($productData['image'])) {
unset($productData['image']);
$productData['image'][0]['name'] = $collcetion->getData('image');
$productData['image'][0]['url'] = $this->imageHelper->getBaseUrl().$collcetion->getData('image');
}
$this->_loadedData[$collcetion->getId()] = $productData;
}
return $this->_loadedData;
}
After do that, it will be work.
Magento 2 image not uploading in edit form
网友评论