55 */
66namespace Magento \Widget \Model \Widget ;
77
8+ use Magento \Catalog \Model \Product \Type ;
9+ use Magento \Framework \App \Cache \TypeListInterface ;
810use Magento \Framework \App \Filesystem \DirectoryList ;
911use Magento \Framework \App \ObjectManager ;
1012use Magento \Framework \Config \Dom \ValidationException ;
1113use Magento \Framework \Config \Dom \ValidationSchemaException ;
14+ use Magento \Framework \Data \Collection \AbstractDb ;
15+ use Magento \Framework \Escaper ;
1216use 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 ;
1324use Magento \Framework \Serialize \Serializer \Json ;
1425use Magento \Framework \Simplexml \Element ;
26+ use Magento \Framework \View \DesignInterface ;
1527use 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 ;
1632
1733/**
1834 * Widget Instance Model
1935 *
2036 * @api
2137 * @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)
2541 * @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)
2844 * @method int getThemeId()
2945 *
3046 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,17 +100,17 @@ class Instance extends \Magento\Framework\Model\AbstractModel
84100 protected $ _viewFileSystem ;
85101
86102 /**
87- * @var \Magento\Widget\Model\ Widget
103+ * @var Widget
88104 */
89105 protected $ _widgetModel ;
90106
91107 /**
92- * @var \Magento\Widget\Model\ NamespaceResolver
108+ * @var NamespaceResolver
93109 */
94110 protected $ _namespaceResolver ;
95111
96112 /**
97- * @var \Magento\Framework\App\Cache\ TypeListInterface
113+ * @var TypeListInterface
98114 */
99115 protected $ _cacheTypeList ;
100116
@@ -104,34 +120,34 @@ class Instance extends \Magento\Framework\Model\AbstractModel
104120 protected $ _relatedCacheTypes ;
105121
106122 /**
107- * @var \Magento\Catalog\Model\Product\ Type
123+ * @var Type
108124 * @since 101.0.4
109125 */
110126 protected $ _productType ;
111127
112128 /**
113- * @var \Magento\Widget\Model\Config\ Reader
129+ * @var Reader
114130 * @since 101.0.4
115131 */
116132 protected $ _reader ;
117133
118134 /**
119- * @var \Magento\Framework\ Escaper
135+ * @var Escaper
120136 */
121137 protected $ _escaper ;
122138
123139 /**
124- * @var \Magento\Framework\Math\ Random
140+ * @var Random
125141 */
126142 protected $ mathRandom ;
127143
128144 /**
129- * @var \Magento\Framework\Filesystem\Directory\ ReadInterface
145+ * @var ReadInterface
130146 */
131147 protected $ _directory ;
132148
133149 /**
134- * @var \Magento\Widget\Helper\ Conditions
150+ * @var Conditions
135151 */
136152 protected $ conditionsHelper ;
137153
@@ -146,41 +162,42 @@ class Instance extends \Magento\Framework\Model\AbstractModel
146162 private $ xmlValidatorFactory ;
147163
148164 /**
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
152168 * @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
163179 * @param array $relatedCacheTypes
164180 * @param array $data
165- * @param \Magento\Framework\Serialize\Serializer\ Json $serializer
181+ * @param Json|null $serializer
166182 * @param ValidatorFactory|null $xmlValidatorFactory
183+ * @throws LocalizedException
167184 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
168185 */
169186 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 ,
173190 \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 ,
184201 array $ relatedCacheTypes = [],
185202 array $ data = [],
186203 Json $ serializer = null ,
@@ -206,6 +223,7 @@ public function __construct(
206223 * Internal Constructor
207224 *
208225 * @return void
226+ * @throws LocalizedException
209227 */
210228 protected function _construct ()
211229 {
@@ -235,6 +253,7 @@ protected function _construct()
235253 * @return $this
236254 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
237255 * @SuppressWarnings(PHPMD.NPathComplexity)
256+ * @throws LocalizedException
238257 */
239258 public function beforeSave ()
240259 {
@@ -271,7 +290,7 @@ public function beforeSave()
271290 foreach (explode (', ' , $ pageGroupData ['entities ' ] ?? '' ) as $ entity ) {
272291 $ layoutHandleUpdates [] = str_replace (
273292 '{{ID}} ' ,
274- $ entity ,
293+ trim ( $ entity) ,
275294 $ this ->_specificEntitiesLayoutHandles [$ pageGroup ['page_group ' ]]
276295 );
277296 }
@@ -290,7 +309,7 @@ public function beforeSave()
290309 if (array_key_exists ('show_pager ' , $ parameters ) && !array_key_exists ('page_var_name ' , $ parameters )) {
291310 $ parameters ['page_var_name ' ] = 'p ' . $ this ->mathRandom ->getRandomString (
292311 5 ,
293- \ Magento \ Framework \ Math \ Random::CHARS_LOWERS
312+ Random::CHARS_LOWERS
294313 );
295314 }
296315
@@ -305,7 +324,7 @@ public function beforeSave()
305324 /**
306325 * Validate widget instance data
307326 *
308- * @return \Magento\Framework\ Phrase|bool
327+ * @return Phrase|bool
309328 */
310329 public function validate ()
311330 {
@@ -391,7 +410,7 @@ public function getArea()
391410 {
392411 //TODO Shouldn't we get "area" from theme model which we can load using "theme_id"?
393412 if (!$ this ->_getData ('area ' )) {
394- return \ Magento \ Framework \ View \ DesignInterface::DEFAULT_AREA ;
413+ return DesignInterface::DEFAULT_AREA ;
395414 }
396415 return $ this ->_getData ('area ' );
397416 }
@@ -628,6 +647,7 @@ private function getWidgetTemplatesFromConfig(
628647 * @return string
629648 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
630649 * @SuppressWarnings(PHPMD.NPathComplexity)
650+ * @throws LocalizedException
631651 */
632652 public function generateLayoutUpdateXml ($ container , $ templatePath = '' )
633653 {
@@ -750,6 +770,7 @@ public function afterSave()
750770 * Invalidate related cache if instance contain layout updates
751771 *
752772 * @return $this
773+ * @throws LocalizedException
753774 */
754775 public function beforeDelete ()
755776 {
0 commit comments