Skip to content

Commit 03e28d1

Browse files
ENGCOM-8010: #1712: Remove DataObject usage from OpenDialogUrl provider #29491
- Merge Pull Request #29491 from joweecaquicla/magento2:1712-remove-dataobject-usage-from-opendialogurl-provider - Merged commits: 1. 68b35c5 2. 7f115fd 3. 0192ca5 4. e2f2805 5. 94bc7c7
2 parents 4930963 + 94bc7c7 commit 03e28d1

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

app/code/Magento/MediaGalleryIntegration/Model/OpenDialogUrlProvider.php renamed to app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MediaGalleryIntegration\Model;
8+
namespace Magento\MediaGalleryIntegration\Plugin;
99

10-
use Magento\Framework\DataObject;
1110
use Magento\MediaGalleryUiApi\Api\ConfigInterface;
11+
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
1212

1313
/**
14-
* Provider to get open media gallery dialog URL for WYSIWYG and widgets
14+
* Plugin to get open media gallery dialog URL for WYSIWYG and widgets
1515
*/
16-
class OpenDialogUrlProvider extends DataObject
16+
class NewMediaGalleryOpenDialogUrl
1717
{
1818
/**
1919
* @var ConfigInterface
@@ -31,10 +31,13 @@ public function __construct(ConfigInterface $config)
3131
/**
3232
* Get Url based on media gallery configuration
3333
*
34+
* @param OpenDialogUrl $subject
35+
* @param string $result
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3437
* @return string
3538
*/
36-
public function getUrl(): string
39+
public function afterGet(OpenDialogUrl $subject, string $result)
3740
{
38-
return $this->config->isEnabled() ? 'media_gallery/index/index' : 'cms/wysiwyg_images/index';
41+
return $this->config->isEnabled() ? 'media_gallery/index/index' : $result;
3942
}
4043
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
namespace Magento\MediaGalleryIntegration\Test\Integration\Model;
1010

1111
use Magento\Framework\ObjectManagerInterface;
12-
use Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider;
1312
use Magento\MediaGalleryUiApi\Api\ConfigInterface;
1413
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
1515
use PHPUnit\Framework\TestCase;
1616

1717
/**
1818
* Provide tests cover getting correct url based on the config settings.
1919
* @magentoAppArea adminhtml
2020
*/
21-
class OpenDialogUrlProviderTest extends TestCase
21+
class OpenDialogUrlTest extends TestCase
2222
{
2323
/**
2424
* @var ObjectManagerInterface
2525
*/
2626
private $objectManger;
2727

2828
/**
29-
* @var OpenDialogUrlProvider
29+
* @var OpenDialogUrl
3030
*/
31-
private $openDialogUrlProvider;
31+
private $openDialogUrl;
3232

3333
/**
3434
* @inheritdoc
@@ -37,8 +37,8 @@ protected function setUp(): void
3737
{
3838
$this->objectManger = Bootstrap::getObjectManager();
3939
$config = $this->objectManger->create(ConfigInterface::class);
40-
$this->openDialogUrlProvider = $this->objectManger->create(
41-
OpenDialogUrlProvider::class,
40+
$this->openDialogUrl = $this->objectManger->create(
41+
OpenDialogUrl::class,
4242
['config' => $config]
4343
);
4444
}
@@ -49,7 +49,7 @@ protected function setUp(): void
4949
*/
5050
public function testWithEnhancedMediaGalleryDisabled(): void
5151
{
52-
self::assertEquals('cms/wysiwyg_images/index', $this->openDialogUrlProvider->getUrl());
52+
self::assertEquals('cms/wysiwyg_images/index', $this->openDialogUrl->get());
5353
}
5454

5555
/**
@@ -58,6 +58,6 @@ public function testWithEnhancedMediaGalleryDisabled(): void
5858
*/
5959
public function testWithEnhancedMediaGalleryEnabled(): void
6060
{
61-
self::assertEquals('media_gallery/index/index', $this->openDialogUrlProvider->getUrl());
61+
self::assertEquals('media_gallery/index/index', $this->openDialogUrl->get());
6262
}
6363
}

app/code/Magento/MediaGalleryIntegration/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"magento/framework": "*",
77
"magento/module-media-gallery-ui-api": "*",
88
"magento/module-media-gallery-api": "*",
9-
"magento/module-media-gallery-synchronization-api": "*"
9+
"magento/module-media-gallery-synchronization-api": "*",
10+
"magento/module-ui": "*"
1011
},
1112
"require-dev": {
1213
"magento/module-cms": "*"

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<type name="Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl">
10-
<arguments>
11-
<argument name="url" xsi:type="object">Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider</argument>
12-
</arguments>
10+
<plugin name="new_media_gallery_open_dialog_url" type="Magento\MediaGalleryIntegration\Plugin\NewMediaGalleryOpenDialogUrl" />
1311
</type>
1412
<type name="Magento\Framework\File\Uploader">
1513
<plugin name="save_asset_image" type="Magento\MediaGalleryIntegration\Plugin\SaveImageInformation"/>

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
namespace Magento\Ui\Component\Form\Element\DataType\Media;
1010

11-
use Magento\Framework\DataObject;
12-
1311
/**
14-
* Basic configuration for OdenDialogUrl
12+
* Basic configuration for OpenDialogUrl
1513
*/
1614
class OpenDialogUrl
1715
{
@@ -23,11 +21,11 @@ class OpenDialogUrl
2321
private $openDialogUrl;
2422

2523
/**
26-
* @param DataObject $url
24+
* @param string $url
2725
*/
28-
public function __construct(DataObject $url = null)
26+
public function __construct(string $url = null)
2927
{
30-
$this->openDialogUrl = $url;
28+
$this->openDialogUrl = $url ?? self::DEFAULT_OPEN_DIALOG_URL;
3129
}
3230

3331
/**
@@ -37,9 +35,6 @@ public function __construct(DataObject $url = null)
3735
*/
3836
public function get(): string
3937
{
40-
if ($this->openDialogUrl) {
41-
return $this->openDialogUrl->getUrl();
42-
}
43-
return self::DEFAULT_OPEN_DIALOG_URL;
38+
return $this->openDialogUrl;
4439
}
4540
}

0 commit comments

Comments
 (0)