Skip to content

Commit 17e3e45

Browse files
committed
Merge branch 'MAGETWO-87986-Media-Folder-Structure-CMS-Images' of github.com:magento-trigger/magento2ce into MAGETWO-87986-Media-Folder-Structure-CMS-Images
2 parents 2028ccd + 5df29ba commit 17e3e45

File tree

13 files changed

+59
-7
lines changed

13 files changed

+59
-7
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/Tree.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,19 @@ public function getTreeJson()
9595
*/
9696
public function getTreeLoaderUrl()
9797
{
98+
$params = [
99+
'use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root')
100+
];
101+
102+
$currentTreePath = $this->getRequest()->getParam('current_tree_path');
103+
104+
if (strlen($currentTreePath)) {
105+
$params['current_tree_path'] = $currentTreePath;
106+
}
107+
98108
return $this->getUrl(
99109
'cms/*/treeJson',
100-
['use_storage_root' => (int) $this->getRequest()->getParam('use_storage_root')]
110+
$params
101111
);
102112
}
103113

@@ -119,7 +129,14 @@ public function getRootNodeName()
119129
public function getTreeCurrentPath()
120130
{
121131
$treePath = ['root'];
122-
if ($path = $this->_coreRegistry->registry('storage')->getSession()->getCurrentPath()) {
132+
133+
if ($idEncodedPath = $this->getRequest()->getParam('current_tree_path')) {
134+
$path = base64_decode($idEncodedPath);
135+
} else {
136+
$path = $this->_coreRegistry->registry('storage')->getSession()->getCurrentPath();
137+
}
138+
139+
if (strlen($path)) {
123140
$path = str_replace($this->_cmsWysiwygImages->getStorageRoot(), '', $path);
124141
$relative = [];
125142
foreach (explode('/', $path) as $dirName) {
@@ -129,6 +146,7 @@ public function getTreeCurrentPath()
129146
}
130147
}
131148
}
149+
132150
return $treePath;
133151
}
134152

app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ define([
8484
recursiveOpen = function () {
8585
var el = $('[data-id="' + path.pop() + '"]');
8686

87-
if (path.length > 1) {
87+
if (path.length) {
8888
tree.jstree('open_node', el, recursiveOpen);
8989
} else {
9090
tree.jstree('open_node', el, function () {

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

Lines changed: 5 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;
@@ -62,6 +65,7 @@ public function prepare()
6265
{
6366
// dynamically set max file size based on php ini config if not present in XML
6467
$maxFileSize = $this->getConfiguration()['maxFileSize'] ?? $this->fileSize->getMaxFileSize();
68+
$initialMediaGalleryOpenSubpath = $this->getConfiguration()['initialMediaGalleryOpenSubpath'];
6569

6670
$data = array_replace_recursive(
6771
$this->getData(),
@@ -71,6 +75,7 @@ public function prepare()
7175
'mediaGallery' => [
7276
'openDialogUrl' => $this->getContext()->getUrl('cms/wysiwyg_images/index'),
7377
'openDialogTitle' => $this->getConfiguration()['openDialogTitle'] ?? __('Insert Images...'),
78+
'initialOpenSubpath' => base64_encode($initialMediaGalleryOpenSubpath),
7479
'storeId' => $this->storeManager->getStore()->getId(),
7580
],
7681
],

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 -->

app/code/Magento/Ui/view/base/ui_component/etc/definition/imageUploader.xsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
</xs:documentation>
3434
</xs:annotation>
3535
</xs:element>
36+
<xs:element name="initialMediaGalleryOpenSubpath" type="xs:string">
37+
<xs:annotation>
38+
<xs:documentation>
39+
Defines the initial subpath relative to root that will be open when opening media gallery
40+
</xs:documentation>
41+
</xs:annotation>
42+
</xs:element>
3643
</xs:choice>
3744
</xs:group>
3845
</xs:schema>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ define([
6767
'/store/' + this.mediaGallery.storeId +
6868
'/type/image/use_storage_root/1?isAjax=true';
6969

70+
if (this.mediaGallery.initialOpenSubpath) {
71+
openDialogUrl += '&current_tree_path=' + this.mediaGallery.initialOpenSubpath;
72+
}
73+
7074
browser.openDialog(openDialogUrl, null, null, this.mediaGallery.openDialogTitle);
7175
},
7276

dev/tests/integration/testsuite/Magento/Ui/_files/view/ui_component/arbitrary/imageUploader.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<item name="anySimpleType" active="false" xsi:type="string">string</item>
1919
</item>
2020
<item name="openDialogTitle" xsi:type="string" translate="true">string</item>
21+
<item name="initialMediaGalleryOpenSubpath" xsi:type="string">string</item>
2122
<item name="visible" xsi:type="boolean">false</item>
2223
<item name="disabled" xsi:type="boolean">false</item>
2324
<item name="labelVisible" xsi:type="boolean">false</item>

dev/tests/integration/testsuite/Magento/Ui/_files/view/ui_component/expected/imageUploader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
'value' => 'string',
5050
'translate' => 'true'
5151
],
52+
'initialMediaGalleryOpenSubpath' => [
53+
'name' => 'initialMediaGalleryOpenSubpath',
54+
'xsi:type' => 'string',
55+
'value' => 'string',
56+
],
5257
'uploaderConfig' => [
5358
'name' => 'uploaderConfig',
5459
'xsi:type' => 'array',

0 commit comments

Comments
 (0)