![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magefan/module-blog/Ui/DataProvider/Category/Form/ |
<?php /** * Copyright © Magefan ([email protected]). All rights reserved. * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). * * Glory to Ukraine! Glory to the heroes! */ namespace Magefan\Blog\Ui\DataProvider\Category\Form; use Magefan\Blog\Model\ResourceModel\Category\CollectionFactory; use Magento\Framework\App\Request\DataPersistorInterface; /** * Class DataProvider */ class CategoryDataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider { /** * @var \Magefan\Blog\Model\ResourceModel\Category\Collection */ protected $collection; /** * @var DataPersistorInterface */ protected $dataPersistor; /** * @var array */ protected $loadedData; /** * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $categoryCollectionFactory * @param DataPersistorInterface $dataPersistor * @param array $meta * @param array $data */ public function __construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $categoryCollectionFactory, DataPersistorInterface $dataPersistor, array $meta = [], array $data = [] ) { $this->collection = $categoryCollectionFactory->create(); $this->dataPersistor = $dataPersistor; parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->meta = $this->prepareMeta($this->meta); } /** * Prepares Meta * * @param array $meta * @return array */ public function prepareMeta(array $meta) { return $meta; } /** * Get data * * @return array */ public function getData() { if (isset($this->loadedData)) { return $this->loadedData; } $items = $this->collection->getItems(); /** @var $category \Magefan\Blog\Model\Category */ foreach ($items as $category) { $category = $category->load($category->getId()); //temporary fix $this->loadedData[$category->getId()] = $category->getData(); } $data = $this->dataPersistor->get('blog_category_form_data'); if (!empty($data)) { $category = $this->collection->getNewEmptyItem(); $category->setData($data); $this->loadedData[$category->getId()] = $category->getData(); $this->dataPersistor->clear('blog_category_form_data'); } return $this->loadedData; } }