12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Cms\Model\Block;
- use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
- use Magento\Framework\App\Request\DataPersistorInterface;
- use Magento\Ui\DataProvider\Modifier\PoolInterface;
- /**
- * Class DataProvider
- */
- class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
- {
- /**
- * @var \Magento\Cms\Model\ResourceModel\Block\Collection
- */
- protected $collection;
- /**
- * @var DataPersistorInterface
- */
- protected $dataPersistor;
- /**
- * @var array
- */
- protected $loadedData;
- /**
- * Constructor
- *
- * @param string $name
- * @param string $primaryFieldName
- * @param string $requestFieldName
- * @param CollectionFactory $blockCollectionFactory
- * @param DataPersistorInterface $dataPersistor
- * @param array $meta
- * @param array $data
- * @param PoolInterface|null $pool
- */
- public function __construct(
- $name,
- $primaryFieldName,
- $requestFieldName,
- CollectionFactory $blockCollectionFactory,
- DataPersistorInterface $dataPersistor,
- array $meta = [],
- array $data = [],
- PoolInterface $pool = null
- ) {
- $this->collection = $blockCollectionFactory->create();
- $this->dataPersistor = $dataPersistor;
- parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
- }
- /**
- * Get data
- *
- * @return array
- */
- public function getData()
- {
- if (isset($this->loadedData)) {
- return $this->loadedData;
- }
- $items = $this->collection->getItems();
- /** @var \Magento\Cms\Model\Block $block */
- foreach ($items as $block) {
- $this->loadedData[$block->getId()] = $block->getData();
- }
- $data = $this->dataPersistor->get('cms_block');
- if (!empty($data)) {
- $block = $this->collection->getNewEmptyItem();
- $block->setData($data);
- $this->loadedData[$block->getId()] = $block->getData();
- $this->dataPersistor->clear('cms_block');
- }
- return $this->loadedData;
- }
- }
|