mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 17:27:36 +00:00
86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?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;
|
|
}
|
|
}
|