| Current Path : /home/rtorresani/www/vendor/magento/module-media-gallery-ui/Model/Listing/ |
| Current File : //home/rtorresani/www/vendor/magento/module-media-gallery-ui/Model/Listing/DataProvider.php |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\MediaGalleryUi\Model\Listing;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\ReportingInterface;
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory;
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider as UiComponentDataProvider;
use Magento\MediaGalleryUi\Ui\Component\Listing\Provider;
/**
* Media gallery UI data provider. Try catch added for displaying errors in grid
*/
class DataProvider extends UiComponentDataProvider
{
/**
* @var CollectionProcessorInterface
*/
private $collectionProcessor;
/**
* @var CollectionFactory
*/
private $collectionFactory;
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param ReportingInterface $reporting
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param RequestInterface $request
* @param FilterBuilder $filterBuilder
* @param CollectionProcessorInterface $collectionProcessor
* @param CollectionFactory $collectionFactory
* @param array $meta
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
ReportingInterface $reporting,
SearchCriteriaBuilder $searchCriteriaBuilder,
RequestInterface $request,
FilterBuilder $filterBuilder,
CollectionProcessorInterface $collectionProcessor,
CollectionFactory $collectionFactory,
array $meta = [],
array $data = []
) {
parent::__construct(
$name,
$primaryFieldName,
$requestFieldName,
$reporting,
$searchCriteriaBuilder,
$request,
$filterBuilder,
$meta,
$data
);
$this->collectionFactory = $collectionFactory;
$this->collectionProcessor = $collectionProcessor;
}
/**
* @inheritdoc
*/
public function getData(): array
{
try {
return $this->searchResultToOutput($this->getSearchResult());
} catch (\Exception $exception) {
return [
'items' => [],
'totalRecords' => 0,
'errorMessage' => $exception->getMessage()
];
}
}
/**
* @inheritDoc
*/
public function getSearchResult(): SearchResultInterface
{
/** @var Provider $collection */
$collection = $this->collectionFactory->getReport($this->getSearchCriteria()->getRequestName());
$this->collectionProcessor->process($this->getSearchCriteria(), $collection);
return $collection;
}
}