Skip to content

Commit 68b35c5

Browse files
author
joweecaquicla
committed
magento/adobe-stock-integration#1712: Remove DataObject usage from OpenDialogUrl provider - remove data object usage from OpenDialogUrl provider, added new plugin and modified the integration test
1 parent be26941 commit 68b35c5

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGalleryIntegration\Plugin;
9+
10+
use Magento\MediaGalleryUiApi\Api\ConfigInterface;
11+
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
12+
13+
class NewMediaGalleryOpenDialogUrl
14+
{
15+
/**
16+
* @var ConfigInterface
17+
*/
18+
private $config;
19+
20+
/**
21+
* @param ConfigInterface $config
22+
*/
23+
public function __construct(ConfigInterface $config)
24+
{
25+
$this->config = $config;
26+
}
27+
28+
/**
29+
* @param OpenDialogUrl $subject
30+
* @param string $result
31+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
32+
* @return string
33+
*/
34+
public function afterGet(OpenDialogUrl $subject, string $result)
35+
{
36+
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/newmediagalleryplugin.log');
37+
$logger = new \Zend\Log\Logger();
38+
$logger->addWriter($writer);
39+
$logger->debug(__METHOD__);
40+
$logger->debug("PASSING HERE!");
41+
return $this->config->isEnabled() ? 'media_gallery/index/index' : $result;
42+
}
43+
}
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/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: 2 additions & 12 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
{
@@ -22,14 +20,6 @@ class OpenDialogUrl
2220
*/
2321
private $openDialogUrl;
2422

25-
/**
26-
* @param DataObject $url
27-
*/
28-
public function __construct(DataObject $url = null)
29-
{
30-
$this->openDialogUrl = $url;
31-
}
32-
3323
/**
3424
* Returns open dialog url for media browser
3525
*
@@ -38,7 +28,7 @@ public function __construct(DataObject $url = null)
3828
public function get(): string
3929
{
4030
if ($this->openDialogUrl) {
41-
return $this->openDialogUrl->getUrl();
31+
return $this->openDialogUrl;
4232
}
4333
return self::DEFAULT_OPEN_DIALOG_URL;
4434
}

0 commit comments

Comments
 (0)