1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MagePrince |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the mageprince.com license that is |
8
|
|
|
* available through the world-wide-web at this URL: |
9
|
|
|
* https://mageprince.com/end-user-license-agreement |
10
|
|
|
* |
11
|
|
|
* DISCLAIMER |
12
|
|
|
* |
13
|
|
|
* Do not edit or add to this file if you wish to upgrade this extension to newer |
14
|
|
|
* version in the future. |
15
|
|
|
* |
16
|
|
|
* @category MagePrince |
17
|
|
|
* @package Mageprince_Faq |
18
|
|
|
* @copyright Copyright (c) MagePrince (https://mageprince.com/) |
19
|
|
|
* @license https://mageprince.com/end-user-license-agreement |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Mageprince\Faq\Controller\Adminhtml\FaqGroup; |
23
|
|
|
|
24
|
|
|
use Magento\Backend\App\Action; |
|
|
|
|
25
|
|
|
use Magento\Backend\Model\View\Result\Redirect; |
|
|
|
|
26
|
|
|
use Magento\Framework\App\Request\DataPersistorInterface; |
|
|
|
|
27
|
|
|
use Magento\Framework\Controller\ResultInterface; |
|
|
|
|
28
|
|
|
use Magento\Framework\Exception\LocalizedException; |
|
|
|
|
29
|
|
|
use Mageprince\Faq\Model\FaqGroupFactory; |
|
|
|
|
30
|
|
|
use Mageprince\Faq\Model\FaqGroupRepository; |
31
|
|
|
use Mageprince\Faq\Model\ImageUploader; |
32
|
|
|
|
33
|
|
|
class Save extends FaqGroup |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var DataPersistorInterface |
37
|
|
|
*/ |
38
|
|
|
protected $dataPersistor; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var ImageUploader |
42
|
|
|
*/ |
43
|
|
|
protected $imageUploader; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var FaqGroupRepository |
47
|
|
|
*/ |
48
|
|
|
protected $faqGroupRepository; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var FaqGroupFactory |
52
|
|
|
*/ |
53
|
|
|
protected $faqGroupFactory; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Save constructor. |
57
|
|
|
* @param Action\Context $context |
58
|
|
|
* @param FaqGroupFactory $faqGroupFactory |
59
|
|
|
* @param DataPersistorInterface $dataPersistor |
60
|
|
|
* @param ImageUploader $imageUploader |
61
|
|
|
* @param FaqGroupRepository $faqGroupRepository |
62
|
|
|
*/ |
63
|
|
|
public function __construct( |
64
|
|
|
Action\Context $context, |
|
|
|
|
65
|
|
|
FaqGroupFactory $faqGroupFactory, |
66
|
|
|
DataPersistorInterface $dataPersistor, |
67
|
|
|
ImageUploader $imageUploader, |
68
|
|
|
FaqGroupRepository $faqGroupRepository |
69
|
|
|
) { |
70
|
|
|
$this->dataPersistor = $dataPersistor; |
71
|
|
|
$this->faqGroupFactory = $faqGroupFactory; |
72
|
|
|
$this->imageUploader = $imageUploader; |
73
|
|
|
$this->faqGroupRepository = $faqGroupRepository; |
74
|
|
|
parent::__construct($context); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Save action |
79
|
|
|
* |
80
|
|
|
* @return ResultInterface |
81
|
|
|
*/ |
82
|
|
|
public function execute() |
83
|
|
|
{ |
84
|
|
|
/** @var Redirect $resultRedirect */ |
85
|
|
|
$resultRedirect = $this->resultRedirectFactory->create(); |
86
|
|
|
|
87
|
|
|
if ($data = $this->getRequest()->getPostValue()) { |
88
|
|
|
$model = $this->faqGroupFactory->create(); |
89
|
|
|
try { |
90
|
|
|
if ($id = (int) $this->getRequest()->getParam('faqgroup_id')) { |
91
|
|
|
$model = $this->faqGroupRepository->getById($id); |
92
|
|
|
if ($id != $model->getId()) { |
|
|
|
|
93
|
|
|
$this->messageManager->addErrorMessage(__('This FAQ Group no longer exists.')); |
|
|
|
|
94
|
|
|
return $resultRedirect->setPath('*/*/'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$data = $this->_filterFaqGroupData($data); |
99
|
|
|
$model->addData($data); |
100
|
|
|
$this->faqGroupRepository->save($model); |
101
|
|
|
$this->messageManager->addSuccessMessage(__('You saved the FAQ Group.')); |
102
|
|
|
$this->dataPersistor->clear('prince_faq_faqgroup'); |
103
|
|
|
|
104
|
|
|
if ($this->getRequest()->getParam('back')) { |
105
|
|
|
return $resultRedirect->setPath('*/*/edit', ['faqgroup_id' => $model->getId()]); |
106
|
|
|
} |
107
|
|
|
return $resultRedirect->setPath('*/*/'); |
108
|
|
|
} catch (LocalizedException $e) { |
109
|
|
|
$this->messageManager->addErrorMessage($e->getMessage()); |
110
|
|
|
} catch (\Exception $e) { |
111
|
|
|
$this->messageManager->addExceptionMessage( |
112
|
|
|
$e, |
113
|
|
|
__('Something went wrong while saving the Faqgroup.') |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$this->dataPersistor->set('prince_faq_faqgroup', $data); |
118
|
|
|
return $resultRedirect->setPath( |
119
|
|
|
'*/*/edit', |
120
|
|
|
[ |
121
|
|
|
'faqgroup_id' => $this->getRequest()->getParam('faqgroup_id') |
122
|
|
|
] |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
return $resultRedirect->setPath('*/*/'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Filter faq group data |
130
|
|
|
* |
131
|
|
|
* @param array $rawData |
132
|
|
|
* @return array |
133
|
|
|
*/ |
134
|
|
|
protected function _filterFaqGroupData(array $rawData) |
135
|
|
|
{ |
136
|
|
|
$data = $rawData; |
137
|
|
|
if (isset($data['icon'][0]['name'])) { |
138
|
|
|
$data['icon'] = $data['icon'][0]['name']; |
139
|
|
|
} else { |
140
|
|
|
$data['icon'] = null; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$cGroup = $data['customer_group']; |
144
|
|
|
if (isset($cGroup)) { |
145
|
|
|
$customerGroup = implode(',', $data['customer_group']); |
146
|
|
|
$data['customer_group'] = $customerGroup; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$stores = $data['storeview']; |
150
|
|
|
if (isset($stores)) { |
151
|
|
|
$store = implode(',', $data['storeview']); |
152
|
|
|
$data['storeview'] = $store; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return $data; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths