![]() 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/cartforge.co/app/code/Magefan/Blog/Ui/DataProvider/Tag/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\Tag\Form; use Magefan\Blog\Model\ResourceModel\Tag\CollectionFactory; use Magento\Framework\App\Request\DataPersistorInterface; /** * Class DataProvider */ class TagDataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider { /** * @var \Magefan\Blog\Model\ResourceModel\Tag\Collection */ protected $collection; /** * @var DataPersistorInterface */ protected $dataPersistor; /** * @var array */ protected $loadedData; /** * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $tagCollectionFactory * @param DataPersistorInterface $dataPersistor * @param array $meta * @param array $data */ public function __construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $tagCollectionFactory, DataPersistorInterface $dataPersistor, array $meta = [], array $data = [] ) { $this->collection = $tagCollectionFactory->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 $tag \Magefan\Blog\Model\Tag */ foreach ($items as $tag) { $tag = $tag->load($tag->getId()); //temporary fix $data = $tag->getData(); /* Prepare Featured Image */ $map = [ 'tag_img' => 'getTagImage', ]; foreach ($map as $key => $method) { if (isset($data[$key])) { $name = $data[$key]; unset($data[$key]); $data[$key][0] = [ 'name' => $name, 'url' => $tag->$method(), ]; } } $this->loadedData[$tag->getId()] = $data; } $data = $this->dataPersistor->get('blog_tag_form_data'); if (!empty($data)) { $tag = $this->collection->getNewEmptyItem(); $tag->setData($data); $this->loadedData[$tag->getId()] = $tag->getData(); $this->dataPersistor->clear('blog_tag_form_data'); } return $this->loadedData; } }