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\Block\CollectionFactory;
11 
16 {
20  protected $collection;
21 
25  protected $dataPersistor;
26 
30  protected $loadedData;
31 
44  public function __construct(
45  $name,
48  CollectionFactory $blockCollectionFactory,
50  array $meta = [],
51  array $data = [],
52  PoolInterface $pool = null
53  ) {
54  $this->collection = $blockCollectionFactory->create();
55  $this->dataPersistor = $dataPersistor;
56  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
57  }
58 
64  public function getData()
65  {
66  if (isset($this->loadedData)) {
67  return $this->loadedData;
68  }
69  $items = $this->collection->getItems();
71  foreach ($items as $block) {
72  $this->loadedData[$block->getId()] = $block->getData();
73  }
74 
75  $data = $this->dataPersistor->get('cms_block');
76  if (!empty($data)) {
77  $block = $this->collection->getNewEmptyItem();
78  $block->setData($data);
79  $this->loadedData[$block->getId()] = $block->getData();
80  $this->dataPersistor->clear('cms_block');
81  }
82 
83  return $this->loadedData;
84  }
85 }
__construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $blockCollectionFactory, DataPersistorInterface $dataPersistor, array $meta=[], array $data=[], PoolInterface $pool=null)
$block
Definition: block.php:8
$items