Skip to content

#1712: Remove DataObject usage from OpenDialogUrl provider #29491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "*"
Copy link
Member

@sivaschenko sivaschenko Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a pull request to https://github.com/magento/partners-magento2-infrastructure with an update to composer etalon (see https://github.com/magento/partners-magento2-infrastructure/pull/19 for example) and cross reference the pull requests as related in the description

},
"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;
}
}