Let’s initiate a discussion!!
1) Create or override the listing.xml file and add the below code
1 2 3 4 5 6 7 8 |
<column name="custom_image" component="Magento_Ui/js/grid/columns/thumbnail" class="Vendor\Module\Ui\Component\Listing\Column\Thumbnail"> <settings> <filter>text</filter> <label translate="true">Custom Image</label> <hasPreview>1</hasPreview> <sortable>false</sortable> </settings> </column> |
2) Create Thumbnail.php and add the below code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
<?php namespace Vendor\Module\Ui\Component\Listing\Column; use Magento\Framework\UrlInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Store\Model\StoreManagerInterface; use Magento\Ui\Component\Listing\Columns\Column; class Thumbnail extends Column { const NAME = 'thumbnail'; const URL_PATH_EDIT = 'moudle/controller/edit'; /** * @var StoreManagerInterface */ protected $storeManager; /** * @var UrlInterface */ protected $url; /** * Image constructor. * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory * @param StoreManagerInterface $storeManager * @param UrlInterface $url * @param array $components * @param array $data */ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, StoreManagerInterface $storeManager, UrlInterface $url, array $components = [], array $data = [], \Magento\Theme\Block\Html\Header\Logo $logo ) { parent::__construct($context, $uiComponentFactory, $components, $data); $this->storeManager = $storeManager; $this->url = $url; $this->_logo = $logo; } /** * Prepare Data Source * * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource) { $mediaUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA); if (isset($dataSource['data']['items'])) { $fieldName = 'custom_image'; foreach ($dataSource['data']['items'] as & $item) { if (!empty($item['custom_image'])) { $name = $item['custom_image']; $item[$fieldName . '_src'] = $mediaUrl.'custom/image'.$name; $item[$fieldName . '_alt'] = ''; $item[$fieldName . '_link'] = $this->url->getUrl(static::URL_PATH_EDIT, [ 'id' => $item['id'] ]); $item[$fieldName . '_orig_src'] = $mediaUrl.'custom/image'.$name; } } } return $dataSource; } } |
[crayon-641efa551d674412663903/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.