5
5
*/
6
6
namespace Magento \Widget \Model \Widget ;
7
7
8
+ use Magento \Catalog \Model \Product \Type ;
9
+ use Magento \Framework \App \Cache \TypeListInterface ;
8
10
use Magento \Framework \App \Filesystem \DirectoryList ;
9
11
use Magento \Framework \App \ObjectManager ;
10
12
use Magento \Framework \Config \Dom \ValidationException ;
11
13
use Magento \Framework \Config \Dom \ValidationSchemaException ;
14
+ use Magento \Framework \Data \Collection \AbstractDb ;
15
+ use Magento \Framework \Escaper ;
12
16
use Magento \Framework \Exception \LocalizedException ;
17
+ use Magento \Framework \Filesystem ;
18
+ use Magento \Framework \Filesystem \Directory \ReadInterface ;
19
+ use Magento \Framework \Math \Random ;
20
+ use Magento \Framework \Model \Context ;
21
+ use Magento \Framework \Model \ResourceModel \AbstractResource ;
22
+ use Magento \Framework \Phrase ;
23
+ use Magento \Framework \Registry ;
13
24
use Magento \Framework \Serialize \Serializer \Json ;
14
25
use Magento \Framework \Simplexml \Element ;
26
+ use Magento \Framework \View \DesignInterface ;
15
27
use Magento \Framework \View \Model \Layout \Update \ValidatorFactory ;
28
+ use Magento \Widget \Helper \Conditions ;
29
+ use Magento \Widget \Model \Config \Reader ;
30
+ use Magento \Widget \Model \NamespaceResolver ;
31
+ use Magento \Widget \Model \Widget ;
16
32
17
33
/**
18
34
* Widget Instance Model
19
35
*
20
36
* @api
21
37
* @method string getTitle()
22
- * @method \Magento\Widget\Model\Widget\ Instance setTitle(string $value)
23
- * @method \Magento\Widget\Model\Widget\ Instance setStoreIds(string $value)
24
- * @method \Magento\Widget\Model\Widget\ Instance setWidgetParameters(string|array $value)
38
+ * @method Instance setTitle(string $value)
39
+ * @method Instance setStoreIds(string $value)
40
+ * @method Instance setWidgetParameters(string|array $value)
25
41
* @method int getSortOrder()
26
- * @method \Magento\Widget\Model\Widget\ Instance setSortOrder(int $value)
27
- * @method \Magento\Widget\Model\Widget\ Instance setThemeId(int $value)
42
+ * @method Instance setSortOrder(int $value)
43
+ * @method Instance setThemeId(int $value)
28
44
* @method int getThemeId()
29
45
*
30
46
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,17 +100,17 @@ class Instance extends \Magento\Framework\Model\AbstractModel
84
100
protected $ _viewFileSystem ;
85
101
86
102
/**
87
- * @var \Magento\Widget\Model\ Widget
103
+ * @var Widget
88
104
*/
89
105
protected $ _widgetModel ;
90
106
91
107
/**
92
- * @var \Magento\Widget\Model\ NamespaceResolver
108
+ * @var NamespaceResolver
93
109
*/
94
110
protected $ _namespaceResolver ;
95
111
96
112
/**
97
- * @var \Magento\Framework\App\Cache\ TypeListInterface
113
+ * @var TypeListInterface
98
114
*/
99
115
protected $ _cacheTypeList ;
100
116
@@ -104,34 +120,34 @@ class Instance extends \Magento\Framework\Model\AbstractModel
104
120
protected $ _relatedCacheTypes ;
105
121
106
122
/**
107
- * @var \Magento\Catalog\Model\Product\ Type
123
+ * @var Type
108
124
* @since 101.0.4
109
125
*/
110
126
protected $ _productType ;
111
127
112
128
/**
113
- * @var \Magento\Widget\Model\Config\ Reader
129
+ * @var Reader
114
130
* @since 101.0.4
115
131
*/
116
132
protected $ _reader ;
117
133
118
134
/**
119
- * @var \Magento\Framework\ Escaper
135
+ * @var Escaper
120
136
*/
121
137
protected $ _escaper ;
122
138
123
139
/**
124
- * @var \Magento\Framework\Math\ Random
140
+ * @var Random
125
141
*/
126
142
protected $ mathRandom ;
127
143
128
144
/**
129
- * @var \Magento\Framework\Filesystem\Directory\ ReadInterface
145
+ * @var ReadInterface
130
146
*/
131
147
protected $ _directory ;
132
148
133
149
/**
134
- * @var \Magento\Widget\Helper\ Conditions
150
+ * @var Conditions
135
151
*/
136
152
protected $ conditionsHelper ;
137
153
@@ -146,41 +162,42 @@ class Instance extends \Magento\Framework\Model\AbstractModel
146
162
private $ xmlValidatorFactory ;
147
163
148
164
/**
149
- * @param \Magento\Framework\Model\ Context $context
150
- * @param \Magento\Framework\ Registry $registry
151
- * @param \Magento\Framework\ Escaper $escaper
165
+ * @param Context $context
166
+ * @param Registry $registry
167
+ * @param Escaper $escaper
152
168
* @param \Magento\Framework\View\FileSystem $viewFileSystem
153
- * @param \Magento\Framework\App\Cache\ TypeListInterface $cacheTypeList
154
- * @param \Magento\Catalog\Model\Product\ Type $productType
155
- * @param \Magento\Widget\Model\Config\ Reader $reader
156
- * @param \Magento\Widget\Model\ Widget $widgetModel
157
- * @param \Magento\Widget\Model\ NamespaceResolver $namespaceResolver
158
- * @param \Magento\Framework\Math\ Random $mathRandom
159
- * @param \Magento\Framework\ Filesystem $filesystem
160
- * @param \Magento\Widget\Helper\ Conditions $conditionsHelper
161
- * @param \Magento\Framework\Model\ResourceModel\ AbstractResource $resource
162
- * @param \Magento\Framework\Data\Collection\ AbstractDb $resourceCollection
169
+ * @param TypeListInterface $cacheTypeList
170
+ * @param Type $productType
171
+ * @param Reader $reader
172
+ * @param Widget $widgetModel
173
+ * @param NamespaceResolver $namespaceResolver
174
+ * @param Random $mathRandom
175
+ * @param Filesystem $filesystem
176
+ * @param Conditions $conditionsHelper
177
+ * @param AbstractResource|null $resource
178
+ * @param AbstractDb|null $resourceCollection
163
179
* @param array $relatedCacheTypes
164
180
* @param array $data
165
- * @param \Magento\Framework\Serialize\Serializer\ Json $serializer
181
+ * @param Json|null $serializer
166
182
* @param ValidatorFactory|null $xmlValidatorFactory
183
+ * @throws LocalizedException
167
184
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
168
185
*/
169
186
public function __construct (
170
- \ Magento \ Framework \ Model \ Context $ context ,
171
- \ Magento \ Framework \ Registry $ registry ,
172
- \ Magento \ Framework \ Escaper $ escaper ,
187
+ Context $ context ,
188
+ Registry $ registry ,
189
+ Escaper $ escaper ,
173
190
\Magento \Framework \View \FileSystem $ viewFileSystem ,
174
- \ Magento \ Framework \ App \ Cache \ TypeListInterface $ cacheTypeList ,
175
- \ Magento \ Catalog \ Model \ Product \ Type $ productType ,
176
- \ Magento \ Widget \ Model \ Config \ Reader $ reader ,
177
- \ Magento \ Widget \ Model \ Widget $ widgetModel ,
178
- \ Magento \ Widget \ Model \ NamespaceResolver $ namespaceResolver ,
179
- \ Magento \ Framework \ Math \ Random $ mathRandom ,
180
- \ Magento \ Framework \ Filesystem $ filesystem ,
181
- \ Magento \ Widget \ Helper \ Conditions $ conditionsHelper ,
182
- \ Magento \ Framework \ Model \ ResourceModel \ AbstractResource $ resource = null ,
183
- \ Magento \ Framework \ Data \ Collection \ AbstractDb $ resourceCollection = null ,
191
+ TypeListInterface $ cacheTypeList ,
192
+ Type $ productType ,
193
+ Reader $ reader ,
194
+ Widget $ widgetModel ,
195
+ NamespaceResolver $ namespaceResolver ,
196
+ Random $ mathRandom ,
197
+ Filesystem $ filesystem ,
198
+ Conditions $ conditionsHelper ,
199
+ AbstractResource $ resource = null ,
200
+ AbstractDb $ resourceCollection = null ,
184
201
array $ relatedCacheTypes = [],
185
202
array $ data = [],
186
203
Json $ serializer = null ,
@@ -206,6 +223,7 @@ public function __construct(
206
223
* Internal Constructor
207
224
*
208
225
* @return void
226
+ * @throws LocalizedException
209
227
*/
210
228
protected function _construct ()
211
229
{
@@ -235,6 +253,7 @@ protected function _construct()
235
253
* @return $this
236
254
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
237
255
* @SuppressWarnings(PHPMD.NPathComplexity)
256
+ * @throws LocalizedException
238
257
*/
239
258
public function beforeSave ()
240
259
{
@@ -271,7 +290,7 @@ public function beforeSave()
271
290
foreach (explode (', ' , $ pageGroupData ['entities ' ] ?? '' ) as $ entity ) {
272
291
$ layoutHandleUpdates [] = str_replace (
273
292
'{{ID}} ' ,
274
- $ entity ,
293
+ trim ( $ entity) ,
275
294
$ this ->_specificEntitiesLayoutHandles [$ pageGroup ['page_group ' ]]
276
295
);
277
296
}
@@ -290,7 +309,7 @@ public function beforeSave()
290
309
if (array_key_exists ('show_pager ' , $ parameters ) && !array_key_exists ('page_var_name ' , $ parameters )) {
291
310
$ parameters ['page_var_name ' ] = 'p ' . $ this ->mathRandom ->getRandomString (
292
311
5 ,
293
- \ Magento \ Framework \ Math \ Random::CHARS_LOWERS
312
+ Random::CHARS_LOWERS
294
313
);
295
314
}
296
315
@@ -305,7 +324,7 @@ public function beforeSave()
305
324
/**
306
325
* Validate widget instance data
307
326
*
308
- * @return \Magento\Framework\ Phrase|bool
327
+ * @return Phrase|bool
309
328
*/
310
329
public function validate ()
311
330
{
@@ -391,7 +410,7 @@ public function getArea()
391
410
{
392
411
//TODO Shouldn't we get "area" from theme model which we can load using "theme_id"?
393
412
if (!$ this ->_getData ('area ' )) {
394
- return \ Magento \ Framework \ View \ DesignInterface::DEFAULT_AREA ;
413
+ return DesignInterface::DEFAULT_AREA ;
395
414
}
396
415
return $ this ->_getData ('area ' );
397
416
}
@@ -628,6 +647,7 @@ private function getWidgetTemplatesFromConfig(
628
647
* @return string
629
648
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
630
649
* @SuppressWarnings(PHPMD.NPathComplexity)
650
+ * @throws LocalizedException
631
651
*/
632
652
public function generateLayoutUpdateXml ($ container , $ templatePath = '' )
633
653
{
@@ -750,6 +770,7 @@ public function afterSave()
750
770
* Invalidate related cache if instance contain layout updates
751
771
*
752
772
* @return $this
773
+ * @throws LocalizedException
753
774
*/
754
775
public function beforeDelete ()
755
776
{
0 commit comments