Skip to content

Commit

Permalink
ENGCOM-8010: #1712: Remove DataObject usage from OpenDialogUrl provider
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldagama authored Aug 19, 2020
2 parents 54633c4 + 03e28d1 commit a528201
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/
declare(strict_types=1);

namespace Magento\MediaGalleryIntegration\Model;
namespace Magento\MediaGalleryIntegration\Plugin;

use Magento\Framework\DataObject;
use Magento\MediaGalleryUiApi\Api\ConfigInterface;
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;

/**
* Provider to get open media gallery dialog URL for WYSIWYG and widgets
* Plugin to get open media gallery dialog URL for WYSIWYG and widgets
*/
class OpenDialogUrlProvider extends DataObject
class NewMediaGalleryOpenDialogUrl
{
/**
* @var ConfigInterface
Expand All @@ -31,10 +31,13 @@ public function __construct(ConfigInterface $config)
/**
* Get Url based on media gallery configuration
*
* @param OpenDialogUrl $subject
* @param string $result
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @return string
*/
public function getUrl(): string
public function afterGet(OpenDialogUrl $subject, string $result)
{
return $this->config->isEnabled() ? 'media_gallery/index/index' : 'cms/wysiwyg_images/index';
return $this->config->isEnabled() ? 'media_gallery/index/index' : $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
namespace Magento\MediaGalleryIntegration\Test\Integration\Model;

use Magento\Framework\ObjectManagerInterface;
use Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider;
use Magento\MediaGalleryUiApi\Api\ConfigInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
use PHPUnit\Framework\TestCase;

/**
* Provide tests cover getting correct url based on the config settings.
* @magentoAppArea adminhtml
*/
class OpenDialogUrlProviderTest extends TestCase
class OpenDialogUrlTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManger;

/**
* @var OpenDialogUrlProvider
* @var OpenDialogUrl
*/
private $openDialogUrlProvider;
private $openDialogUrl;

/**
* @inheritdoc
Expand All @@ -37,8 +37,8 @@ protected function setUp(): void
{
$this->objectManger = Bootstrap::getObjectManager();
$config = $this->objectManger->create(ConfigInterface::class);
$this->openDialogUrlProvider = $this->objectManger->create(
OpenDialogUrlProvider::class,
$this->openDialogUrl = $this->objectManger->create(
OpenDialogUrl::class,
['config' => $config]
);
}
Expand All @@ -49,7 +49,7 @@ protected function setUp(): void
*/
public function testWithEnhancedMediaGalleryDisabled(): void
{
self::assertEquals('cms/wysiwyg_images/index', $this->openDialogUrlProvider->getUrl());
self::assertEquals('cms/wysiwyg_images/index', $this->openDialogUrl->get());
}

/**
Expand All @@ -58,6 +58,6 @@ public function testWithEnhancedMediaGalleryDisabled(): void
*/
public function testWithEnhancedMediaGalleryEnabled(): void
{
self::assertEquals('media_gallery/index/index', $this->openDialogUrlProvider->getUrl());
self::assertEquals('media_gallery/index/index', $this->openDialogUrl->get());
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/MediaGalleryIntegration/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"magento/framework": "*",
"magento/module-media-gallery-ui-api": "*",
"magento/module-media-gallery-api": "*",
"magento/module-media-gallery-synchronization-api": "*"
"magento/module-media-gallery-synchronization-api": "*",
"magento/module-ui": "*"
},
"require-dev": {
"magento/module-cms": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl">
<arguments>
<argument name="url" xsi:type="object">Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider</argument>
</arguments>
<plugin name="new_media_gallery_open_dialog_url" type="Magento\MediaGalleryIntegration\Plugin\NewMediaGalleryOpenDialogUrl" />
</type>
<type name="Magento\Framework\File\Uploader">
<plugin name="save_asset_image" type="Magento\MediaGalleryIntegration\Plugin\SaveImageInformation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

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

use Magento\Framework\DataObject;

/**
* Basic configuration for OdenDialogUrl
* Basic configuration for OpenDialogUrl
*/
class OpenDialogUrl
{
Expand All @@ -23,11 +21,11 @@ class OpenDialogUrl
private $openDialogUrl;

/**
* @param DataObject $url
* @param string $url
*/
public function __construct(DataObject $url = null)
public function __construct(string $url = null)
{
$this->openDialogUrl = $url;
$this->openDialogUrl = $url ?? self::DEFAULT_OPEN_DIALOG_URL;
}

/**
Expand All @@ -37,9 +35,6 @@ public function __construct(DataObject $url = null)
*/
public function get(): string
{
if ($this->openDialogUrl) {
return $this->openDialogUrl->getUrl();
}
return self::DEFAULT_OPEN_DIALOG_URL;
return $this->openDialogUrl;
}
}

0 comments on commit a528201

Please sign in to comment.