3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Cms \Helper \Wysiwyg ;
7
8
9
+ use Exception ;
10
+ use InvalidArgumentException ;
11
+ use Magento \Backend \Helper \Data ;
8
12
use Magento \Framework \App \Filesystem \DirectoryList ;
9
- use Magento \Framework \Exception \ValidatorException ;
13
+ use Magento \Framework \App \Helper \AbstractHelper ;
14
+ use Magento \Framework \App \Helper \Context ;
15
+ use Magento \Framework \Escaper ;
16
+ use Magento \Framework \Exception \FileSystemException ;
17
+ use Magento \Framework \Exception \LocalizedException ;
18
+ use Magento \Framework \Filesystem ;
19
+ use Magento \Framework \Filesystem \Directory \Read ;
20
+ use Magento \Framework \Filesystem \Directory \Write ;
21
+ use Magento \Framework \UrlInterface ;
22
+ use Magento \Store \Model \StoreManagerInterface ;
23
+ use Magento \Theme \Helper \Storage ;
10
24
11
25
/**
12
26
* Wysiwyg Images Helper.
13
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
28
*/
15
- class Images extends \ Magento \ Framework \ App \ Helper \ AbstractHelper
29
+ class Images extends AbstractHelper
16
30
{
17
31
/**
18
32
* Image directory subpath relative to media directory
@@ -23,12 +37,14 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper
23
37
24
38
/**
25
39
* Current directory path
40
+ *
26
41
* @var string
27
42
*/
28
43
protected $ _currentPath ;
29
44
30
45
/**
31
46
* Current directory URL
47
+ *
32
48
* @var string
33
49
*/
34
50
protected $ _currentUrl ;
@@ -41,51 +57,51 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper
41
57
protected $ _storeId ;
42
58
43
59
/**
44
- * @var \Magento\Framework\Filesystem\Directory\ Write
60
+ * @var Write
45
61
*/
46
62
protected $ _directory ;
47
63
48
64
/**
49
65
* Adminhtml data
50
66
*
51
- * @var \Magento\Backend\Helper\ Data
67
+ * @var Data
52
68
*/
53
69
protected $ _backendData ;
54
70
55
71
/**
56
72
* Store manager
57
73
*
58
- * @var \Magento\Store\Model\ StoreManagerInterface
74
+ * @var StoreManagerInterface
59
75
*/
60
76
protected $ _storeManager ;
61
77
62
78
/**
63
79
* String escaper
64
80
*
65
- * @var \Magento\Framework\ Escaper
81
+ * @var Escaper
66
82
*/
67
83
protected $ escaper ;
68
84
69
85
/**
70
- * @var \Magento\Framework\Filesystem\Directory\ Read
86
+ * @var Read
71
87
*/
72
88
private $ _readDirectory ;
73
89
74
90
/**
75
91
* Construct
76
92
*
77
- * @param \Magento\Framework\App\Helper\ Context $context
78
- * @param \Magento\Backend\Helper\ Data $backendData
79
- * @param \Magento\Framework\ Filesystem $filesystem
80
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
81
- * @param \Magento\Framework\ Escaper $escaper
93
+ * @param Context $context
94
+ * @param Data $backendData
95
+ * @param Filesystem $filesystem
96
+ * @param StoreManagerInterface $storeManager
97
+ * @param Escaper $escaper
82
98
*/
83
99
public function __construct (
84
- \ Magento \ Framework \ App \ Helper \ Context $ context ,
85
- \ Magento \ Backend \ Helper \ Data $ backendData ,
86
- \ Magento \ Framework \ Filesystem $ filesystem ,
87
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
88
- \ Magento \ Framework \ Escaper $ escaper
100
+ Context $ context ,
101
+ Data $ backendData ,
102
+ Filesystem $ filesystem ,
103
+ StoreManagerInterface $ storeManager ,
104
+ Escaper $ escaper
89
105
) {
90
106
parent ::__construct ($ context );
91
107
$ this ->_backendData = $ backendData ;
@@ -136,7 +152,7 @@ public function getStorageRootSubpath()
136
152
*/
137
153
public function getBaseUrl ()
138
154
{
139
- return $ this ->_storeManager ->getStore ()->getBaseUrl (\ Magento \ Framework \ UrlInterface::URL_TYPE_MEDIA );
155
+ return $ this ->_storeManager ->getStore ()->getBaseUrl (UrlInterface::URL_TYPE_MEDIA );
140
156
}
141
157
142
158
/**
@@ -166,19 +182,19 @@ public function convertPathToId($path)
166
182
*
167
183
* @param string $id
168
184
* @return string
169
- * @throws \ InvalidArgumentException
185
+ * @throws InvalidArgumentException
170
186
*/
171
187
public function convertIdToPath ($ id )
172
188
{
173
- if ($ id === \ Magento \ Theme \ Helper \ Storage::NODE_ROOT ) {
189
+ if ($ id === Storage::NODE_ROOT ) {
174
190
return $ this ->getStorageRoot ();
175
191
} else {
176
192
$ path = $ this ->getStorageRoot () . $ this ->idDecode ($ id );
177
193
178
194
try {
179
195
$ this ->_readDirectory ->getAbsolutePath ($ path );
180
- } catch (\ Exception $ e ) {
181
- throw new \ InvalidArgumentException ('Path is invalid ' );
196
+ } catch (Exception $ e ) {
197
+ throw new InvalidArgumentException ('Path is invalid ' );
182
198
}
183
199
184
200
return $ path ;
@@ -192,7 +208,7 @@ public function convertIdToPath($id)
192
208
*/
193
209
public function isUsingStaticUrlsAllowed ()
194
210
{
195
- $ checkResult = (object ) [];
211
+ $ checkResult = (object )[];
196
212
$ checkResult ->isAllowed = false ;
197
213
$ this ->_eventManager ->dispatch (
198
214
'cms_wysiwyg_images_static_urls_allowed ' ,
@@ -211,7 +227,7 @@ public function isUsingStaticUrlsAllowed()
211
227
public function getImageHtmlDeclaration ($ filename , $ renderAsTag = false )
212
228
{
213
229
$ fileUrl = $ this ->getCurrentUrl () . $ filename ;
214
- $ mediaUrl = $ this ->_storeManager ->getStore ()->getBaseUrl (\ Magento \ Framework \ UrlInterface::URL_TYPE_MEDIA );
230
+ $ mediaUrl = $ this ->_storeManager ->getStore ($ this -> _storeId )->getBaseUrl (UrlInterface::URL_TYPE_MEDIA );
215
231
$ mediaPath = str_replace ($ mediaUrl , '' , $ fileUrl );
216
232
$ directive = sprintf ('{{media url="%s"}} ' , $ mediaPath );
217
233
if ($ renderAsTag ) {
@@ -238,7 +254,7 @@ public function getImageHtmlDeclaration($filename, $renderAsTag = false)
238
254
* Return path of the root directory for startup. Also try to create target directory if it doesn't exist
239
255
*
240
256
* @return string
241
- * @throws \Magento\Framework\Exception\ LocalizedException
257
+ * @throws LocalizedException
242
258
*/
243
259
public function getCurrentPath ()
244
260
{
@@ -268,21 +284,21 @@ public function getCurrentPath()
268
284
* Create subdirectory if doesn't exist
269
285
*
270
286
* @param string $absPath Path of subdirectory to create
271
- * @throws \Magento\Framework\Exception\ LocalizedException
287
+ * @throws LocalizedException
272
288
*/
273
289
private function createSubDirIfNotExist (string $ absPath )
274
290
{
275
291
$ relPath = $ this ->_directory ->getRelativePath ($ absPath );
276
292
if (!$ this ->_directory ->isExist ($ relPath )) {
277
293
try {
278
294
$ this ->_directory ->create ($ relPath );
279
- } catch (\ Magento \ Framework \ Exception \ FileSystemException $ e ) {
295
+ } catch (FileSystemException $ e ) {
280
296
$ message = __ (
281
297
'Can \'t create %1 as subdirectory of %2, you might have some permission issue. ' ,
282
298
$ relPath ,
283
299
$ this ->_directory ->getAbsolutePath ()
284
300
);
285
- throw new \ Magento \ Framework \ Exception \ LocalizedException ($ message );
301
+ throw new LocalizedException ($ message );
286
302
}
287
303
}
288
304
}
@@ -299,7 +315,7 @@ public function getCurrentUrl()
299
315
$ mediaUrl = $ this ->_storeManager ->getStore (
300
316
$ this ->_storeId
301
317
)->getBaseUrl (
302
- \ Magento \ Framework \ UrlInterface::URL_TYPE_MEDIA
318
+ UrlInterface::URL_TYPE_MEDIA
303
319
);
304
320
$ this ->_currentUrl = rtrim ($ mediaUrl . $ this ->_directory ->getRelativePath ($ path ), '/ ' ) . '/ ' ;
305
321
}
0 commit comments