Skip to content

Commit c477172

Browse files
ENGCOM-7295: Improve openDialog method initialization #27566
- Merge Pull Request #27566 from Nazar65/magento2:support-new-media-gallery - Merged commits: 1. c839ecc 2. e5e23a8 3. 7ba5410 4. f8730c9 5. dba6863 6. 2da1025 7. 9b21471 8. 610cd62 9. 26e4df5 10. 8a5def7 11. 2c74e2f 12. 67c2c0c 13. 25e5df1 14. e4cdee3 15. d6fabe2 16. 6f3cc44 17. cbb1f4a 18. b0afe12 19. 8f338a9 20. 9b75b8d 21. 15a1861 22. cdcf858 23. c94a81c 24. edf4017 25. 0abc548 26. 9387809 27. aa82c97 28. 41f7115
2 parents cd77da6 + 41f7115 commit c477172

File tree

11 files changed

+162
-67
lines changed

11 files changed

+162
-67
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
namespace Magento\Cms\Model\Wysiwyg\Gallery;
1010

11+
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
12+
13+
/**
14+
* @inheritdoc
15+
*/
1116
class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
1217
{
1318
/**
@@ -30,26 +35,34 @@ class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigPro
3035
*/
3136
private $currentTreePath;
3237

38+
/**
39+
* @var OpednDialogUrl
40+
*/
41+
private $openDialogUrl;
42+
3343
/**
3444
* @param \Magento\Backend\Model\UrlInterface $backendUrl
3545
* @param \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper
46+
* @param OpenDialogUrl $openDialogUrl
3647
* @param array $windowSize
3748
* @param string|null $currentTreePath
3849
*/
3950
public function __construct(
4051
\Magento\Backend\Model\UrlInterface $backendUrl,
4152
\Magento\Cms\Helper\Wysiwyg\Images $imagesHelper,
53+
OpenDialogUrl $openDialogUrl,
4254
array $windowSize = [],
4355
$currentTreePath = null
4456
) {
4557
$this->backendUrl = $backendUrl;
4658
$this->imagesHelper = $imagesHelper;
59+
$this->openDialogUrl = $openDialogUrl;
4760
$this->windowSize = $windowSize;
4861
$this->currentTreePath = $currentTreePath;
4962
}
5063

5164
/**
52-
* {@inheritdoc}
65+
* @inheritdoc
5366
*/
5467
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
5568
{
@@ -72,7 +85,7 @@ public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Fram
7285
[
7386
'add_images' => true,
7487
'files_browser_window_url' => $this->backendUrl->getUrl(
75-
'cms/wysiwyg_images/index',
88+
$this->openDialogUrl->get(),
7689
$fileBrowserUrlParams
7790
),
7891
'files_browser_window_width' => $this->windowSize['width'],

app/code/Magento/Tinymce3/Model/Config/Gallery/Config.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Tinymce3\Model\Config\Gallery;
99

10+
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
11+
1012
/**
1113
* Class Config adds information about required configurations to display media gallery of tinymce3 editor
1214
*
@@ -19,13 +21,21 @@ class Config implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
1921
*/
2022
private $backendUrl;
2123

24+
/**
25+
* @var OpednDialogUrl
26+
*/
27+
private $openDialogUrl;
28+
2229
/**
2330
* @param \Magento\Backend\Model\UrlInterface $backendUrl
31+
* @param OpenDialogUrl $openDialogUrl
2432
*/
2533
public function __construct(
26-
\Magento\Backend\Model\UrlInterface $backendUrl
34+
\Magento\Backend\Model\UrlInterface $backendUrl,
35+
OpenDialogUrl $openDialogUrl
2736
) {
2837
$this->backendUrl = $backendUrl;
38+
$this->openDialogUrl = $openDialogUrl;
2939
}
3040

3141
/**
@@ -39,7 +49,7 @@ public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Fram
3949
$config->addData(
4050
[
4151
'add_images' => true,
42-
'files_browser_window_url' => $this->backendUrl->getUrl('cms/wysiwyg_images/index'),
52+
'files_browser_window_url' => $this->backendUrl->getUrl($this->openDialogUrl->get()),
4353
]
4454
);
4555

app/code/Magento/Tinymce3/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"magento/module-backend": "*",
88
"magento/module-ui": "*",
99
"magento/module-variable": "*",
10-
"magento/module-widget": "*",
11-
"magento/module-cms": "*"
10+
"magento/module-widget": "*"
1211

1312
},
1413
"suggest": {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,43 @@ class Image extends Media
3131
*/
3232
private $fileSize;
3333

34+
/**
35+
* @var OpednDialogUrl
36+
*/
37+
private $openDialogUrl;
38+
3439
/**
3540
* @param ContextInterface $context
3641
* @param StoreManagerInterface $storeManager
3742
* @param Size $fileSize
43+
* @param OpenDialogUrl $openDialogUrl
3844
* @param UiComponentInterface[] $components
3945
* @param array $data
4046
*/
4147
public function __construct(
4248
ContextInterface $context,
4349
StoreManagerInterface $storeManager,
4450
Size $fileSize,
51+
OpenDialogUrl $openDialogUrl,
4552
array $components = [],
4653
array $data = []
4754
) {
4855
$this->storeManager = $storeManager;
4956
$this->fileSize = $fileSize;
57+
$this->openDialogUrl = $openDialogUrl;
5058
parent::__construct($context, $components, $data);
5159
}
5260

5361
/**
54-
* {@inheritdoc}
62+
* @inheritdoc
5563
*/
5664
public function getComponentName()
5765
{
5866
return static::NAME;
5967
}
6068

6169
/**
62-
* {@inheritdoc}
70+
* @inheritdoc
6371
*/
6472
public function prepare()
6573
{
@@ -75,7 +83,10 @@ public function prepare()
7583
'config' => [
7684
'maxFileSize' => $maxFileSize,
7785
'mediaGallery' => [
78-
'openDialogUrl' => $this->getContext()->getUrl('cms/wysiwyg_images/index', ['_secure' => true]),
86+
'openDialogUrl' => $this->getContext()->getUrl(
87+
$this->openDialogUrl->get(),
88+
['_secure' => true]
89+
),
7990
'openDialogTitle' => $this->getConfiguration()['openDialogTitle'] ?? __('Insert Images...'),
8091
'initialOpenSubpath' => $this->getConfiguration()['initialMediaGalleryOpenSubpath'],
8192
'storeId' => $this->storeManager->getStore()->getId(),
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Ui\Component\Form\Element\DataType\Media;
10+
11+
use Magento\Framework\DataObject;
12+
13+
/**
14+
* Basic configuration for OdenDialogUrl
15+
*/
16+
class OpenDialogUrl
17+
{
18+
private const DEFAULT_OPEN_DIALOG_URL = 'cms/wysiwyg_images/index';
19+
20+
/**
21+
* @var string
22+
*/
23+
private $openDialogUrl;
24+
25+
/**
26+
* @param DataObject $url
27+
*/
28+
public function __construct(DataObject $url = null)
29+
{
30+
$this->openDialogUrl = $url;
31+
}
32+
33+
/**
34+
* Returns open dialog url for media browser
35+
*
36+
* @return string
37+
*/
38+
public function get(): string
39+
{
40+
if ($this->openDialogUrl) {
41+
return $this->openDialogUrl->getUrl();
42+
}
43+
return self::DEFAULT_OPEN_DIALOG_URL;
44+
}
45+
}

app/code/Magento/Ui/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"magento/module-backend": "*",
1212
"magento/module-eav": "*",
1313
"magento/module-store": "*",
14-
"magento/module-user": "*",
15-
"magento/module-cms": "*"
14+
"magento/module-user": "*"
1615
},
1716
"suggest": {
1817
"magento/module-config": "*"

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ define([
8181
openDialogUrl += '&current_tree_path=' + Base64.mageEncode(this.mediaGallery.initialOpenSubpath);
8282
}
8383

84-
browser.openDialog(openDialogUrl, null, null, this.mediaGallery.openDialogTitle);
84+
browser.openDialog(
85+
openDialogUrl,
86+
null,
87+
null,
88+
this.mediaGallery.openDialogTitle,
89+
{
90+
targetElementId: $buttonEl.attr('id')
91+
}
92+
);
8593
},
8694

8795
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ define([
7878
'?isAjax=true&current_tree_path=d3lzaXd5Zw,,',
7979
null,
8080
null,
81-
'Hello world'
81+
'Hello world',
82+
{
83+
targetElementId: 'theTargetId'
84+
}
8285
);
8386
});
8487
});

dev/tests/js/jasmine/tests/lib/mage/browser.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ define([
3737
*/
3838
done: function () {
3939
obj.targetElementId = 1;
40+
obj.modalLoaded = true;
4041
}
4142
};
4243
});
@@ -58,8 +59,8 @@ define([
5859
}
5960
};
6061
});
61-
obj.openDialog('instance/url', 100, 100, 'title', undefined);
62-
obj.openDialog('instance/url', 100, 100, 'title', undefined);
62+
obj.openDialog('instance/url/target_element_id/YDW2424/', 100, 100, 'title', undefined);
63+
obj.openDialog('instance/target_element_id/Y45GDRg/', 100, 100, 'title', undefined);
6364
expect($.ajax.calls.count()).toBe(1);
6465
});
6566
});

lib/internal/Magento/Framework/Data/Form/Element/Editor.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,19 @@ protected function _getPluginButtonsHtml($visible = true)
286286

287287
// Button to media images insertion window
288288
if ($this->getConfig('add_images')) {
289+
$htmlId = $this->getHtmlId();
290+
$url = $this->getConfig('files_browser_window_url')
291+
. 'target_element_id/'
292+
. $htmlId
293+
. '/'
294+
. (null !== $this->getConfig('store_id')
295+
? 'store/' . $this->getConfig('store_id') . '/"'
296+
: '');
289297
$buttonsHtml .= $this->_getButtonHtml(
290298
[
291299
'title' => $this->translate('Insert Image...'),
292-
'onclick' => "MediabrowserUtility.openDialog('"
293-
. $this->getConfig('files_browser_window_url')
294-
. "target_element_id/" . $this->getHtmlId() . "/"
295-
. (null !== $this->getConfig('store_id') ? 'store/'
296-
. $this->getConfig('store_id') . '/' : '')
297-
. "')",
300+
'onclick' => 'MediabrowserUtility.openDialog(\'' . $url
301+
. '\', null, null, null, { \'targetElementId\': \'' . $htmlId . '\' })',
298302
'class' => 'action-add-image plugin',
299303
'style' => $visible ? '' : 'display:none',
300304
]
@@ -496,13 +500,13 @@ protected function getInlineJs($jsSetupObject, $forceLoad)
496500
$jsString = '
497501
<script type="text/javascript">
498502
//<![CDATA[
499-
window.tinyMCE_GZ = window.tinyMCE_GZ || {};
503+
window.tinyMCE_GZ = window.tinyMCE_GZ || {};
500504
window.tinyMCE_GZ.loaded = true;
501505
require([
502-
"jquery",
503-
"mage/translate",
504-
"mage/adminhtml/events",
505-
"mage/adminhtml/wysiwyg/tiny_mce/setup",
506+
"jquery",
507+
"mage/translate",
508+
"mage/adminhtml/events",
509+
"mage/adminhtml/wysiwyg/tiny_mce/setup",
506510
"mage/adminhtml/wysiwyg/widget"
507511
], function(jQuery){' .
508512
"\n" .

0 commit comments

Comments
 (0)