Skip to content

Commit 43e65fa

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents 909af53 + 620d37d commit 43e65fa

File tree

33 files changed

+145
-66
lines changed

33 files changed

+145
-66
lines changed

app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
</uploaderConfig>
174174
<previewTmpl>Magento_Catalog/image-preview</previewTmpl>
175175
<openDialogTitle>Media Gallery</openDialogTitle>
176+
<initialMediaGalleryOpenSubpath>catalog/category</initialMediaGalleryOpenSubpath>
176177
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
177178
<maxFileSize>4194304</maxFileSize>
178179
</settings>

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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ public function getTreeJson()
9595
*/
9696
public function getTreeLoaderUrl()
9797
{
98+
$params = [];
99+
100+
$currentTreePath = $this->getRequest()->getParam('current_tree_path');
101+
102+
if (strlen($currentTreePath)) {
103+
$params['current_tree_path'] = $currentTreePath;
104+
}
105+
98106
return $this->getUrl(
99107
'cms/*/treeJson',
100-
['use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root')]
108+
$params
101109
);
102110
}
103111

@@ -119,7 +127,14 @@ public function getRootNodeName()
119127
public function getTreeCurrentPath()
120128
{
121129
$treePath = ['root'];
122-
if ($path = $this->_coreRegistry->registry('storage')->getSession()->getCurrentPath()) {
130+
131+
if ($idEncodedPath = $this->getRequest()->getParam('current_tree_path')) {
132+
$path = $this->_cmsWysiwygImages->idDecode($idEncodedPath);
133+
} else {
134+
$path = $this->_coreRegistry->registry('storage')->getSession()->getCurrentPath();
135+
}
136+
137+
if (strlen($path)) {
123138
$path = str_replace($this->_cmsWysiwygImages->getStorageRoot(), '', $path);
124139
$relative = [];
125140
foreach (explode('/', $path) as $dirName) {
@@ -129,6 +144,7 @@ public function getTreeCurrentPath()
129144
}
130145
}
131146
}
147+
132148
return $treePath;
133149
}
134150

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Ui\Component\Form\Element\DataType\Media;
710

811
use Magento\Store\Model\StoreManagerInterface;
@@ -71,6 +74,7 @@ public function prepare()
7174
'mediaGallery' => [
7275
'openDialogUrl' => $this->getContext()->getUrl('cms/wysiwyg_images/index'),
7376
'openDialogTitle' => $this->getConfiguration()['openDialogTitle'] ?? __('Insert Images...'),
77+
'initialOpenSubpath' => $this->getConfiguration()['initialMediaGalleryOpenSubpath'],
7478
'storeId' => $this->storeManager->getStore()->getId(),
7579
],
7680
],

app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@
362362
<item name="openDialogTitle" type="string" xsi:type="xpath">
363363
formElements/*[name(.)=../../@formElement]/settings/openDialogTitle
364364
</item>
365+
<item name="initialMediaGalleryOpenSubpath" type="string" xsi:type="xpath">
366+
formElements/*[name(.)=../../@formElement]/settings/initialMediaGalleryOpenSubpath
367+
</item>
365368
<item name="customEntry" type="string" xsi:type="xpath">
366369
formElements/*[name(.)=../../@formElement]/settings/customEntry
367370
</item>
@@ -427,6 +430,7 @@
427430
<argument name="data" xsi:type="array">
428431
<item name="config" xsi:type="array">
429432
<item name="openDialogTitle" type="string" translate="true" xsi:type="xpath">settings/openDialogTitle</item>
433+
<item name="initialMediaGalleryOpenSubpath" type="string" xsi:type="xpath">settings/initialMediaGalleryOpenSubpath</item>
430434
</item>
431435
</argument>
432436
</schema>

app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@
144144
<multiline class="Magento\Ui\Component\Form\Element\Multiline" component="Magento_Ui/js/form/components/group"/>
145145
<range class="Magento\Ui\Component\Form\Element\Range" component="Magento_Ui/js/grid/filters/range"/>
146146
<fileUploader class="Magento\Ui\Component\Form\Element\DataType\Media" component="Magento_Ui/js/form/element/file-uploader" template="ui/form/element/uploader/uploader"/>
147-
<imageUploader class="Magento\Ui\Component\Form\Element\DataType\Media\Image" component="Magento_Ui/js/form/element/image-uploader" template="ui/form/element/uploader/image"/>
147+
<imageUploader class="Magento\Ui\Component\Form\Element\DataType\Media\Image" component="Magento_Ui/js/form/element/image-uploader" template="ui/form/element/uploader/image">
148+
<settings>
149+
<initialMediaGalleryOpenSubpath>wysiwyg</initialMediaGalleryOpenSubpath>
150+
</settings>
151+
</imageUploader>
148152
<!-- Form elements -->
149153

150154
<!-- Form element data types -->

0 commit comments

Comments
 (0)