b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / SR / Theme / Model / Theme /
Filename/home/dev2.destoffenstraat.com/app/code/SR/Theme/Model/Theme/DataProvider.php
Size2.64 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified06-Apr-2021 18:06
Last accessed22-Aug-2025 14:01
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php


namespace SR\Theme\Model\Theme;

use Magento\Framework\App\Request\DataPersistorInterface;
use SR\Theme\Model\ResourceModel\Theme\CollectionFactory;
use \Magento\Store\Model\StoreManagerInterface;

class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
{

protected $dataPersistor;

protected $collection;

protected $loadedData;

/**
* Constructor
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param DataPersistorInterface $dataPersistor
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
DataPersistorInterface $dataPersistor,
StoreManagerInterface $storemanager,
array $meta = [],
array $data = []
) {
$this->collection = $collectionFactory->create();
$this->dataPersistor = $dataPersistor;
$this->_storeManager = $storemanager;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}

/**
* Get data
*
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
foreach ($items as $model) {
if($model->getImage()){
$m['image'][0]['name'] = $model->getImage();
$m['image'][0]['file'] = $model->getImage();
$m['image'][0]['type'] = 'image/'.pathinfo($model->getImage(), PATHINFO_EXTENSION);
$m['image'][0]['previewType'] = 'image';
$m['image'][0]['url'] = $this->getMediaUrl().$model->getImage();

$this->loadedData[$model->getId()] = array_merge($model->getData(),$m);
} else {
$this->loadedData[$model->getId()] = $model->getData();
}
}
$data = $this->dataPersistor->get('sr_theme_theme');

if (!empty($data)) {
$model = $this->collection->getNewEmptyItem();
$model->setData($data);
$this->loadedData[$model->getId()] = $model->getData();
$this->dataPersistor->clear('sr_theme_theme');
}

return $this->loadedData;
}


public function getMediaUrl()
{
$mediaUrl = $this->_storeManager->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'srtheme/';
return $mediaUrl;
}
}