Skip to content

Commit fb232d5

Browse files
committed
MAGETWO-87986: Media Folder Structure for CMS Images
Use universal pub/media storage root
1 parent 81c0ce0 commit fb232d5

File tree

9 files changed

+60
-38
lines changed

9 files changed

+60
-38
lines changed

app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Content.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public function getContentsUrl()
9494
{
9595
return $this->getUrl('cms/*/contents', [
9696
'type' => $this->getRequest()->getParam('type'),
97-
'use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root'),
9897
]);
9998
}
10099

@@ -143,9 +142,7 @@ public function getNewfolderUrl()
143142
*/
144143
protected function getDeletefolderUrl()
145144
{
146-
return $this->getUrl('cms/*/deleteFolder', [
147-
'use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root'),
148-
]);
145+
return $this->getUrl('cms/*/deleteFolder');
149146
}
150147

151148
/**
@@ -165,9 +162,7 @@ public function getDeleteFilesUrl()
165162
*/
166163
public function getOnInsertUrl()
167164
{
168-
return $this->getUrl('cms/*/onInsert', [
169-
'use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root'),
170-
]);
165+
return $this->getUrl('cms/*/onInsert');
171166
}
172167

173168
/**

app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public function getTreeJson()
9595
*/
9696
public function getTreeLoaderUrl()
9797
{
98-
$params = [
99-
'use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root')
100-
];
98+
$params = [];
10199

102100
$currentTreePath = $this->getRequest()->getParam('current_tree_path');
103101

app/code/Magento/Cms/Helper/Wysiwyg/Images.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public function getStorageRoot()
120120
*/
121121
public function getStorageRootSubpath()
122122
{
123-
return $this->_getRequest()->getParam('use_storage_root')
124-
? ''
125-
: \Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY;
123+
return '';
126124
}
127125

128126
/**

app/code/Magento/Cms/Model/Wysiwyg/Gallery/DefaultConfigProvider.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,37 @@ class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigPro
1313
*/
1414
private $backendUrl;
1515

16+
/**
17+
* @var \Magento\Cms\Helper\Wysiwyg\Images
18+
*/
19+
private $imagesHelper;
20+
1621
/**
1722
* @var array
1823
*/
1924
private $windowSize;
2025

26+
/**
27+
* @var string|null
28+
*/
29+
private $currentTreePath;
30+
2131
/**
2232
* @param \Magento\Backend\Model\UrlInterface $backendUrl
33+
* @param \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper
2334
* @param array $windowSize
35+
* @param string|null $currentTreePath
2436
*/
25-
public function __construct(\Magento\Backend\Model\UrlInterface $backendUrl, array $windowSize = [])
26-
{
37+
public function __construct(
38+
\Magento\Backend\Model\UrlInterface $backendUrl,
39+
\Magento\Cms\Helper\Wysiwyg\Images $imagesHelper,
40+
array $windowSize = [],
41+
$currentTreePath = null
42+
) {
2743
$this->backendUrl = $backendUrl;
44+
$this->imagesHelper = $imagesHelper;
2845
$this->windowSize = $windowSize;
46+
$this->currentTreePath = $currentTreePath;
2947
}
3048

3149
/**
@@ -39,10 +57,22 @@ public function getConfig($config)
3957
'name' => 'image',
4058
]
4159
];
60+
61+
$fileBrowserUrlParams = [];
62+
63+
if (is_string($this->currentTreePath)) {
64+
$fileBrowserUrlParams = [
65+
'current_tree_path' => $this->imagesHelper->idEncode($this->currentTreePath),
66+
];
67+
}
68+
4269
return $config->addData(
4370
[
4471
'add_images' => true,
45-
'files_browser_window_url' => $this->backendUrl->getUrl('cms/wysiwyg_images/index'),
72+
'files_browser_window_url' => $this->backendUrl->getUrl(
73+
'cms/wysiwyg_images/index',
74+
$fileBrowserUrlParams
75+
),
4676
'files_browser_window_width' => $this->windowSize['width'],
4777
'files_browser_window_height' => $this->windowSize['height'],
4878
'plugins' => array_merge($pluginData, $imageData)

app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ImagesTest extends \PHPUnit\Framework\TestCase
7979

8080
protected function setUp()
8181
{
82-
$this->path = 'PATH/';
82+
$this->path = 'PATH';
8383
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
8484

8585
$this->eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
@@ -111,6 +111,7 @@ protected function setUp()
111111
[
112112
[WysiwygConfig::IMAGE_DIRECTORY, null, $this->getAbsolutePath(WysiwygConfig::IMAGE_DIRECTORY)],
113113
[null, null, $this->getAbsolutePath(null)],
114+
['', null, $this->getAbsolutePath('')],
114115
]
115116
);
116117

@@ -179,7 +180,7 @@ public function testSetStoreId()
179180
public function testGetStorageRoot()
180181
{
181182
$this->assertEquals(
182-
$this->getAbsolutePath(WysiwygConfig::IMAGE_DIRECTORY),
183+
$this->getAbsolutePath(''),
183184
$this->imagesHelper->getStorageRoot()
184185
);
185186
}
@@ -203,7 +204,7 @@ public function testGetTreeNodeName()
203204
public function testConvertPathToId()
204205
{
205206
$pathOne = '/test_path';
206-
$pathTwo = $this->getAbsolutePath(WysiwygConfig::IMAGE_DIRECTORY) . '/test_path';
207+
$pathTwo = $this->getAbsolutePath('') . '/test_path';
207208
$this->assertEquals(
208209
$this->imagesHelper->convertPathToId($pathOne),
209210
$this->imagesHelper->convertPathToId($pathTwo)
@@ -345,26 +346,25 @@ public function testGetCurrentPath($pathId, $expectedPath, $isExist)
345346
->willReturnMap(
346347
[
347348
['node', null, $pathId],
348-
['use_storage_root', null, false],
349349
]
350350
);
351351

352352
$this->directoryWriteMock->expects($this->any())
353353
->method('isDirectory')
354354
->willReturnMap(
355355
[
356-
['/../wysiwyg/test_path', true],
357-
['/../wysiwyg/my.jpg', false],
358-
['/../wysiwyg', true],
356+
['/../test_path', true],
357+
['/../my.jpg', false],
358+
['.', true],
359359
]
360360
);
361361
$this->directoryWriteMock->expects($this->any())
362362
->method('getRelativePath')
363363
->willReturnMap(
364364
[
365-
['PATH/wysiwyg/test_path', '/../wysiwyg/test_path'],
366-
['PATH/wysiwyg/my.jpg', '/../wysiwyg/my.jpg'],
367-
['PATH/wysiwyg', '/../wysiwyg'],
365+
['PATH/test_path', '/../test_path'],
366+
['PATH/my.jpg', '/../my.jpg'],
367+
['PATH', '.'],
368368
]
369369
);
370370
$this->directoryWriteMock->expects($this->once())
@@ -401,12 +401,12 @@ public function testGetCurrentPathThrowException()
401401
public function providerGetCurrentPath()
402402
{
403403
return [
404-
['L3Rlc3RfcGF0aA--', 'PATH/wysiwyg/test_path', true],
405-
['L215LmpwZw--', 'PATH/wysiwyg', true],
406-
[null, 'PATH/wysiwyg', true],
407-
['L3Rlc3RfcGF0aA--', 'PATH/wysiwyg/test_path', false],
408-
['L215LmpwZw--', 'PATH/wysiwyg', false],
409-
[null, 'PATH/wysiwyg', false],
404+
['L3Rlc3RfcGF0aA--', 'PATH/test_path', true],
405+
['L215LmpwZw--', 'PATH', true],
406+
[null, 'PATH', true],
407+
['L3Rlc3RfcGF0aA--', 'PATH/test_path', false],
408+
['L215LmpwZw--', 'PATH', false],
409+
[null, 'PATH', false],
410410
];
411411
}
412412

app/code/Magento/Cms/etc/adminhtml/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</type>
4141
<type name="Magento\Cms\Model\Wysiwyg\Gallery\DefaultConfigProvider">
4242
<arguments>
43+
<argument name="currentTreePath" xsi:type="const">\Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY</argument>
4344
<argument name="windowSize" xsi:type="array">
4445
<item name="height" xsi:type="number">600</item>
4546
<item name="width" xsi:type="number">1000</item>

app/code/Magento/Ui/Component/Form/Element/DataType/Media/Image.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function prepare()
6565
{
6666
// dynamically set max file size based on php ini config if not present in XML
6767
$maxFileSize = $this->getConfiguration()['maxFileSize'] ?? $this->fileSize->getMaxFileSize();
68-
$initialMediaGalleryOpenSubpath = $this->getConfiguration()['initialMediaGalleryOpenSubpath'];
6968

7069
$data = array_replace_recursive(
7170
$this->getData(),
@@ -75,7 +74,7 @@ public function prepare()
7574
'mediaGallery' => [
7675
'openDialogUrl' => $this->getContext()->getUrl('cms/wysiwyg_images/index'),
7776
'openDialogTitle' => $this->getConfiguration()['openDialogTitle'] ?? __('Insert Images...'),
78-
'initialOpenSubpath' => base64_encode($initialMediaGalleryOpenSubpath),
77+
'initialOpenSubpath' => $this->getConfiguration()['initialMediaGalleryOpenSubpath'],
7978
'storeId' => $this->storeManager->getStore()->getId(),
8079
],
8180
],

app/code/Magento/Ui/view/base/web/js/form/element/image-uploader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See COPYING.txt for license details.
44
*/
55

6+
/* global Base64 */
67
define([
78
'jquery',
89
'underscore',
@@ -55,7 +56,7 @@ define([
5556
},
5657

5758
/**
58-
* Open the media browser dialog using the
59+
* Open the media browser dialog
5960
*
6061
* @param {ImageUploader} imageUploader - UI Class
6162
* @param {Event} e
@@ -65,10 +66,10 @@ define([
6566
openDialogUrl = this.mediaGallery.openDialogUrl +
6667
'target_element_id/' + $buttonEl.attr('id') +
6768
'/store/' + this.mediaGallery.storeId +
68-
'/type/image/use_storage_root/1?isAjax=true';
69+
'/type/image/?isAjax=true';
6970

7071
if (this.mediaGallery.initialOpenSubpath) {
71-
openDialogUrl += '&current_tree_path=' + this.mediaGallery.initialOpenSubpath;
72+
openDialogUrl += '&current_tree_path=' + Base64.mageEncode(this.mediaGallery.initialOpenSubpath);
7273
}
7374

7475
browser.openDialog(openDialogUrl, null, null, this.mediaGallery.openDialogTitle);

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/element/image-uploader.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ define([
7575

7676
expect(browser.openDialog).toHaveBeenCalledWith(
7777
'http://example.com/target_element_id/theTargetId/store/3/type/image/' +
78-
'use_storage_root/1?isAjax=true&current_tree_path=wysiwyg',
78+
'?isAjax=true&current_tree_path=d3lzaXd5Zw,,',
7979
null,
8080
null,
8181
'Hello world'

0 commit comments

Comments
 (0)