I want to display uploaded file in admin edit form using ui component in magento2
How Can i Get this?
and here is fildset.php
<?php
namespace Vendor\Module\Ui\Component\Form;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentInterface;
use Magento\Ui\Component\Form\FieldFactory;
use Magento\Ui\Component\Form\Fieldset as BaseFieldset;
class Fieldset extends BaseFieldset
{
private $fieldFactory;
public function __construct(
ContextInterface $context,
array $components = [],
array $data = [],
FieldFactory $fieldFactory,
\Vendor\Module\Model\Projectsubmit $modelProjectsubmit,
\Magento\Framework\Session\SessionManagerInterface $coreSession,
\Magento\Framework\App\Request\Http $request,
\Magento\Store\Model\StoreManagerInterface $storeManager
)
{
parent::__construct($context, $components, $data);
$this->_coreSession = $coreSession;
$this->_request = $request;
$this->_storeManager = $storeManager;
}
public function getChildComponents()
{
$fields=$this->getFields();
foreach ($fields as $k => $fieldConfig) {
$fieldInstance = $this->fieldFactory->create();
$name = $fieldConfig['name'];
$fieldInstance->setData(
[
'config' => $fieldConfig,
'name' => $name
]
);
$fieldInstance->prepare();
$this->addComponent($name, $fieldInstance);
}
$this->_coreSession->setMaincategory('');
$this->_coreSession->setChildcategory('');
return parent::getChildComponents();
}
function getFields(){
$id=$this->_request->getParam('projectsubmit_id');
$getCategoryData=$this->_modelProjectsubmit->getCollection()->getData();
foreach($getCategoryData as $key=>$value){
if($value['projectsubmit_id']==$id)
{
$mainCategory=$value['main_category'];
$childCategory=$value['child_category'];
$uploadFile=$value['upload_file'];
}
}
$after_html='';
if($uploadFile != '')
{
$result = explode(",",$uploadFile);
foreach ($result as $value)
{
$path = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)."product-popup/".$value;
// $after_html.= '<a href="'.$path.'" target ="_blank">
// <img height="22" width="22" class="small-image-preview v-middle" alt="'.$value.'" title="'.$value.'" id="slider" src="'.$path.'"/></a>';
}
}
$formFields = $this->_modelProjectsubmit->defineFormFields();
$currentform = $formFields[$mainCategory][$childCategory];
foreach($currentform as $key => $formfield) :
if(!(isset($formfield['type'])))
continue;
if($formfield['type'] == "text") {
$fields[]= [
'label' => strip_tags($formfield['label']),
'disabled' => true,
'name' => $formfield['key'],
'formElement' => 'input',
];
}
elseif($formfield['type'] == "radio") {
if($formfield['key'] == "color_preferences") {
$fields[]= [
'label' => 'Color Preferences',
'disabled' => true,
'name' => 'color_preferences',
'formElement' =>'input',
];
}
else
{
$fields[]= [
'label' => strip_tags($formfield['label']),
'disabled' => true,
'name' => $formfield['key'],
'formElement' =>'select',
'options' => $options,
];
// die("<br> in".__FILE__." : ".__LINE__);
}
if(isset($formfield['extratype']) && $formfield['extratype'] == "text") {
$fields[]= [
'label' => "Other Info",
'disabled' => true,
'name' => $formfield['extrakey'],
'formElement' =>'input',
];
}
}
elseif($formfield['type'] == "textarea") {
$fields[]= [
'label' => strip_tags($formfield['label']),
'disabled' => true,
'name' => $formfield['key'],
'formElement' =>'textarea',
];
}
**$fields[]= [
'label' => 'File',
'disabled' => true,
'name' => 'upload_file',
'formElement' =>'fileUploader',
'url' => $after_html
];** ***(i need to set my all logic here)***
endforeach;
return $fields;
}
}
$fields[]= [ 'label' => 'File', 'disabled' => true, 'name' => 'upload_file', 'formElement' =>'fileUploader', 'url' => $after_html ]; please check this part