ltsecurityinc安防产品在线商城代码
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user