Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 38843ff5 authored by Nicolas's avatar Nicolas
Browse files

Affichage d'une thumbnail dans la grille

parent d19738c1
No related branches found
No related tags found
No related merge requests found
<?php
namespace NicolasBejean\ContentManager\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 ALT_FIELD = 'name';
/**
* @var UrlInterface
*/
protected $urlBuilder;
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* Thumbnail constructor.
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
* @param StoreManagerInterface $storeManager
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
StoreManagerInterface $storeManager,
array $components = [],
array $data = []
) {
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if(isset($dataSource['data']['items'])) {
/* Récupère le nom de la colonne concerné */
$fieldName = $this->getData('name');
foreach($dataSource['data']['items'] as & $item) {
$url = '';
if($item[$fieldName] != '') {
$url = $item['image_path'];
}
$item[$fieldName . '_src'] = $url;
$item[$fieldName . '_alt'] = $item['image_alt'] ?: '';
$item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
'nicolasbejeancontentmanager/contentmanager/edit',
['entity_id' => $item['entity_id']]
);
$item[$fieldName . '_orig_src'] = $url;
}
}
return $dataSource;
}
}
......@@ -162,10 +162,11 @@
<label translate="true">Identifier</label>
</settings>
</column>
<column name="image_path" sortOrder="10">
<column name="image_path" sortOrder="10" component="Magento_Ui/js/grid/columns/thumbnail" class="NicolasBejean\ContentManager\Ui\Component\Listing\Column\Thumbnail">
<settings>
<filter>text</filter>
<label translate="true">Image Path</label>
<label translate="true">Thumbnail</label>
<hasPreview>1</hasPreview>
<sortable>false</sortable>
</settings>
</column>
<column name="image_alt" sortOrder="10">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment