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?

1
  • let me know if you have any issue Commented Nov 11, 2017 at 10:04

2 Answers 2

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;
}
1
  • It works fine. But failed to bring image preview(It shows as empty image) and size of the image while editing.
    – Jaisa
    Commented Nov 16, 2017 at 6:24
1

Add this line in your icon condition

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.