Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProvider.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
11 
16 {
20  protected $collection;
21 
25  protected $dataPersistor;
26 
30  protected $loadedData;
31 
42  public function __construct(
43  $name,
46  CollectionFactory $pageCollectionFactory,
48  array $meta = [],
49  array $data = [],
50  PoolInterface $pool = null
51  ) {
52  $this->collection = $pageCollectionFactory->create();
53  $this->dataPersistor = $dataPersistor;
54  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
55  $this->meta = $this->prepareMeta($this->meta);
56  }
57 
64  public function prepareMeta(array $meta)
65  {
66  return $meta;
67  }
68 
74  public function getData()
75  {
76  if (isset($this->loadedData)) {
77  return $this->loadedData;
78  }
79  $items = $this->collection->getItems();
81  foreach ($items as $page) {
82  $this->loadedData[$page->getId()] = $page->getData();
83  }
84 
85  $data = $this->dataPersistor->get('cms_page');
86  if (!empty($data)) {
87  $page = $this->collection->getNewEmptyItem();
88  $page->setData($data);
89  $this->loadedData[$page->getId()] = $page->getData();
90  $this->dataPersistor->clear('cms_page');
91  }
92 
93  return $this->loadedData;
94  }
95 }
__construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $pageCollectionFactory, DataPersistorInterface $dataPersistor, array $meta=[], array $data=[], PoolInterface $pool=null)
$page
Definition: pages.php:8
$items