1

I used this answer to implement ui image uploader in my custom module.

It's working good. But whenever I go into edit the page image is not coming.

How can we show the uploaded image in edit page?

John
  • 827
  • 10
  • 22
Rahul
  • 739
  • 2
  • 17
  • 37

2 Answers2

5

You need to add your custom image uploader data to DataProvider.php

Vendor/Module/Model/FaqGroup/DataProvider.php

public function getData()
{
    ...

    $items = $this->collection->getItems();
    foreach ($items as $model) {
        $this->loadedData[$model->getId()] = $model->getData();
        if ($model->getIcon()) {
            // replace icon to your custom field name
            $m['icon'][0]['name'] = $model->getIcon();
            $m['icon'][0]['url'] = $this->getMediaUrl().$model->getIcon();
            $fullData = $this->loadedData;
            $this->loadedData[$model->getId()] = array_merge($fullData[$model->getId()], $m);
        }
    }

   ...

    return $this->loadedData;
}

public function getMediaUrl()
{
    $mediaUrl = $this->storeManager->getStore()
        ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'faq/tmp/icon/';
    return $mediaUrl;
}
Prince Patel
  • 22,708
  • 10
  • 97
  • 119
  • It works fine. But failed to bring image preview(It shows as empty image) and size of the image while editing. – Jaisa Nov 16 '17 at 06:24
1

Add this line in your icon condition

$m['icon'][0]['type'] = 'image';