78 lines
2.0 KiB
PHP
Executable File
78 lines
2.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright © All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace JR\NetSuite\Model\Location;
|
|
|
|
use Magento\Framework\App\Request\DataPersistorInterface;
|
|
use Magento\Ui\DataProvider\AbstractDataProvider;
|
|
use JR\NetSuite\Model\ResourceModel\Location\CollectionFactory;
|
|
|
|
class DataProvider extends AbstractDataProvider
|
|
{
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $loadedData;
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected $collection;
|
|
|
|
/**
|
|
* @var DataPersistorInterface
|
|
*/
|
|
protected $dataPersistor;
|
|
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param string $primaryFieldName
|
|
* @param string $requestFieldName
|
|
* @param CollectionFactory $collectionFactory
|
|
* @param DataPersistorInterface $dataPersistor
|
|
* @param array $meta
|
|
* @param array $data
|
|
*/
|
|
public function __construct(
|
|
$name,
|
|
$primaryFieldName,
|
|
$requestFieldName,
|
|
CollectionFactory $collectionFactory,
|
|
DataPersistorInterface $dataPersistor,
|
|
array $meta = [],
|
|
array $data = []
|
|
) {
|
|
$this->collection = $collectionFactory->create();
|
|
$this->dataPersistor = $dataPersistor;
|
|
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getData()
|
|
{
|
|
if (isset($this->loadedData)) {
|
|
return $this->loadedData;
|
|
}
|
|
$items = $this->collection->getItems();
|
|
foreach ($items as $model) {
|
|
$this->loadedData[$model->getId()] = $model->getData();
|
|
}
|
|
$data = $this->dataPersistor->get('jr_netsuite_location');
|
|
|
|
if (!empty($data)) {
|
|
$model = $this->collection->getNewEmptyItem();
|
|
$model->setData($data);
|
|
$this->loadedData[$model->getId()] = $model->getData();
|
|
$this->dataPersistor->clear('jr_netsuite_location');
|
|
}
|
|
|
|
return $this->loadedData;
|
|
}
|
|
} |