Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceDataProvider.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
19 
24 {
25  const SOURCE_FORM_NAME = 'inventory_source_form_data_source';
26 
30  private $sourceRepository;
31 
35  private $searchResultFactory;
36 
40  private $session;
41 
57  public function __construct(
58  $name,
65  SourceRepositoryInterface $sourceRepository,
66  SearchResultFactory $searchResultFactory,
67  Session $session,
68  array $meta = [],
69  array $data = []
70  ) {
71  parent::__construct(
72  $name,
75  $reporting,
77  $request,
79  $meta,
80  $data
81  );
82  $this->sourceRepository = $sourceRepository;
83  $this->searchResultFactory = $searchResultFactory;
84  $this->session = $session;
85  }
86 
90  public function getData()
91  {
92  $data = parent::getData();
93  if (self::SOURCE_FORM_NAME === $this->name) {
94  // It is need for support of several fieldsets.
95  // For details see \Magento\Ui\Component\Form::getDataSourceData
96  if ($data['totalRecords'] > 0) {
98  $sourceGeneralData = $data['items'][0];
99  $sourceGeneralData['disable_source_code'] = !empty($sourceGeneralData['source_code']);
100  $dataForSingle[$sourceCode] = [
101  'general' => $sourceGeneralData,
102  ];
103  return $dataForSingle;
104  }
105  $sessionData = $this->session->getSourceFormData(true);
106  if (null !== $sessionData) {
107  // For details see \Magento\Ui\Component\Form::getDataSourceData
108  $data = [
109  '' => $sessionData,
110  ];
111  }
112  }
113  return $data;
114  }
115 
119  public function getSearchResult()
120  {
122  $result = $this->sourceRepository->getList($searchCriteria);
123 
124  $searchResult = $this->searchResultFactory->create(
125  $result->getItems(),
126  $result->getTotalCount(),
129  );
130  return $searchResult;
131  }
132 }
__construct( $name, $primaryFieldName, $requestFieldName, ReportingInterface $reporting, SearchCriteriaBuilder $searchCriteriaBuilder, RequestInterface $request, FilterBuilder $filterBuilder, SourceRepositoryInterface $sourceRepository, SearchResultFactory $searchResultFactory, Session $session, array $meta=[], array $data=[])
$sourceCode
Definition: inventory.phtml:11
$sourceRepository
Definition: source.php:20