Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
DataProvider.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
12 
18 {
22  protected $collection;
23 
27  protected $loadedData;
28 
32  protected $dataPersistor;
33 
43  public function __construct(
44  $name,
47  CollectionFactory $collectionFactory,
49  array $meta = [],
50  array $data = []
51  ) {
52  $this->collection = $collectionFactory->create();
53  $this->dataPersistor = $dataPersistor;
54  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
55  }
56 
60  public function getData()
61  {
62  if (isset($this->loadedData)) {
63  return $this->loadedData;
64  }
65  $items = $this->collection->getItems();
67  foreach ($items as $rule) {
68  $rule->load($rule->getId());
69  $this->loadedData[$rule->getId()] = $rule->getData();
70  }
71 
72  $data = $this->dataPersistor->get('catalog_rule');
73  if (!empty($data)) {
74  $rule = $this->collection->getNewEmptyItem();
75  $rule->setData($data);
76  $this->loadedData[$rule->getId()] = $rule->getData();
77  $this->dataPersistor->clear('catalog_rule');
78  }
79 
80  return $this->loadedData;
81  }
82 }
__construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, DataPersistorInterface $dataPersistor, array $meta=[], array $data=[])
$items