init
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ImageManager\Ui\Component\Listing\Column;
|
||||
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Framework\View\Element\UiComponent\ContextInterface;
|
||||
use Magento\Framework\View\Element\UiComponentFactory;
|
||||
use Magento\Ui\Component\Listing\Columns\Column;
|
||||
|
||||
class Actions extends Column
|
||||
{
|
||||
public function __construct(
|
||||
ContextInterface $context,
|
||||
UiComponentFactory $uiComponentFactory,
|
||||
private readonly UrlInterface $urlBuilder,
|
||||
array $components = [],
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $uiComponentFactory, $components, $data);
|
||||
}
|
||||
|
||||
public function prepareDataSource(array $dataSource): array
|
||||
{
|
||||
if (!isset($dataSource['data']['items'])) {
|
||||
return $dataSource;
|
||||
}
|
||||
|
||||
$fieldName = (string) $this->getData('name');
|
||||
foreach ($dataSource['data']['items'] as &$item) {
|
||||
if (!isset($item['image_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = (int) $item['image_id'];
|
||||
$title = (string) ($item['title'] ?? '');
|
||||
$item[$fieldName]['edit'] = [
|
||||
'href' => $this->urlBuilder->getUrl('esun_image_manager/image/edit', ['id' => $id]),
|
||||
'label' => __('Edit'),
|
||||
];
|
||||
$item[$fieldName]['delete'] = [
|
||||
'href' => $this->urlBuilder->getUrl('esun_image_manager/image/delete', ['id' => $id]),
|
||||
'label' => __('Delete'),
|
||||
'confirm' => [
|
||||
'title' => __('Delete %1', $title),
|
||||
'message' => __('Are you sure you want to delete this image?'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $dataSource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ImageManager\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
|
||||
{
|
||||
public function __construct(
|
||||
ContextInterface $context,
|
||||
UiComponentFactory $uiComponentFactory,
|
||||
private readonly StoreManagerInterface $storeManager,
|
||||
private readonly UrlInterface $urlBuilder,
|
||||
array $components = [],
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $uiComponentFactory, $components, $data);
|
||||
}
|
||||
|
||||
public function prepareDataSource(array $dataSource): array
|
||||
{
|
||||
if (!isset($dataSource['data']['items'])) {
|
||||
return $dataSource;
|
||||
}
|
||||
|
||||
$fieldName = (string) $this->getData('name');
|
||||
$mediaBaseUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
|
||||
foreach ($dataSource['data']['items'] as &$item) {
|
||||
$path = (string) ($item['thumbnail_path'] ?: $item['image_path'] ?: $item['icon_path']);
|
||||
if ($path === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = $mediaBaseUrl . ltrim($path, '/');
|
||||
$item[$fieldName . '_src'] = $url;
|
||||
$item[$fieldName . '_orig_src'] = $url;
|
||||
$item[$fieldName . '_alt'] = (string) ($item['title'] ?? '');
|
||||
$item[$fieldName . '_link'] = $this->urlBuilder->getUrl(
|
||||
'esun_image_manager/image/edit',
|
||||
['id' => (int) $item['image_id']]
|
||||
);
|
||||
}
|
||||
|
||||
return $dataSource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ImageManager\Ui\DataProvider\Image;
|
||||
|
||||
use Esun\ImageManager\Model\ResourceModel\Image\CollectionFactory;
|
||||
use Magento\Framework\Api\Filter;
|
||||
use Magento\Ui\DataProvider\AbstractDataProvider;
|
||||
|
||||
class ListingDataProvider extends AbstractDataProvider
|
||||
{
|
||||
public function __construct(
|
||||
string $name,
|
||||
string $primaryFieldName,
|
||||
string $requestFieldName,
|
||||
CollectionFactory $collectionFactory,
|
||||
array $meta = [],
|
||||
array $data = []
|
||||
) {
|
||||
$this->collection = $collectionFactory->create();
|
||||
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
|
||||
}
|
||||
|
||||
public function addFilter(Filter $filter): void
|
||||
{
|
||||
if ($filter->getField() !== 'fulltext') {
|
||||
parent::addFilter($filter);
|
||||
return;
|
||||
}
|
||||
|
||||
$connection = $this->collection->getConnection();
|
||||
$value = '%' . (string) $filter->getValue() . '%';
|
||||
$this->collection->getSelect()->where(
|
||||
$connection->quoteInto('main_table.title LIKE ?', $value)
|
||||
. ' OR '
|
||||
. $connection->quoteInto('category.name LIKE ?', $value)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user