From 68b35c53c6104121095f6ca89cbe3ddd7e9319ce Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Wed, 12 Aug 2020 19:58:22 +0800 Subject: [PATCH 1/4] 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 --- .../Plugin/NewMediaGalleryOpenDialogUrl.php | 43 +++++++++++++++++++ ...ProviderTest.php => OpenDialogUrlTest.php} | 16 +++---- .../etc/adminhtml/di.xml | 4 +- .../Element/DataType/Media/OpenDialogUrl.php | 14 +----- 4 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php rename app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/{OpenDialogUrlProviderTest.php => OpenDialogUrlTest.php} (80%) diff --git a/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php b/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php new file mode 100644 index 0000000000000..f076aa43b6f96 --- /dev/null +++ b/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php @@ -0,0 +1,43 @@ +config = $config; + } + + /** + * @param OpenDialogUrl $subject + * @param string $result + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @return string + */ + public function afterGet(OpenDialogUrl $subject, string $result) + { + $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/newmediagalleryplugin.log'); + $logger = new \Zend\Log\Logger(); + $logger->addWriter($writer); + $logger->debug(__METHOD__); + $logger->debug("PASSING HERE!"); + return $this->config->isEnabled() ? 'media_gallery/index/index' : $result; + } +} diff --git a/app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/OpenDialogUrlProviderTest.php b/app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/OpenDialogUrlTest.php similarity index 80% rename from app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/OpenDialogUrlProviderTest.php rename to app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/OpenDialogUrlTest.php index 7a3316f293879..90f363d6d792b 100644 --- a/app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/OpenDialogUrlProviderTest.php +++ b/app/code/Magento/MediaGalleryIntegration/Test/Integration/Model/OpenDialogUrlTest.php @@ -9,16 +9,16 @@ 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 @@ -26,9 +26,9 @@ class OpenDialogUrlProviderTest extends TestCase private $objectManger; /** - * @var OpenDialogUrlProvider + * @var OpenDialogUrl */ - private $openDialogUrlProvider; + private $openDialogUrl; /** * @inheritdoc @@ -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] ); } @@ -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()); } /** @@ -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()); } } diff --git a/app/code/Magento/MediaGalleryIntegration/etc/adminhtml/di.xml b/app/code/Magento/MediaGalleryIntegration/etc/adminhtml/di.xml index 1559a6d7dfcd5..08e83ce6cad88 100644 --- a/app/code/Magento/MediaGalleryIntegration/etc/adminhtml/di.xml +++ b/app/code/Magento/MediaGalleryIntegration/etc/adminhtml/di.xml @@ -7,9 +7,7 @@ --> - - Magento\MediaGalleryIntegration\Model\OpenDialogUrlProvider - + diff --git a/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php b/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php index 27370cbfbd68c..cd116a6f1bff8 100644 --- a/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php +++ b/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php @@ -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 { @@ -22,14 +20,6 @@ class OpenDialogUrl */ private $openDialogUrl; - /** - * @param DataObject $url - */ - public function __construct(DataObject $url = null) - { - $this->openDialogUrl = $url; - } - /** * Returns open dialog url for media browser * @@ -38,7 +28,7 @@ public function __construct(DataObject $url = null) public function get(): string { if ($this->openDialogUrl) { - return $this->openDialogUrl->getUrl(); + return $this->openDialogUrl; } return self::DEFAULT_OPEN_DIALOG_URL; } From 7f115fdf42003bd86ee35336e4f4ee85c54de5c9 Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Wed, 12 Aug 2020 20:02:43 +0800 Subject: [PATCH 2/4] magento/adobe-stock-integration#1712: Remove DataObject usage from OpenDialogUrl provider - remove logs --- .../Plugin/NewMediaGalleryOpenDialogUrl.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php b/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php index f076aa43b6f96..13068721634e8 100644 --- a/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php +++ b/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php @@ -33,11 +33,6 @@ public function __construct(ConfigInterface $config) */ public function afterGet(OpenDialogUrl $subject, string $result) { - $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/newmediagalleryplugin.log'); - $logger = new \Zend\Log\Logger(); - $logger->addWriter($writer); - $logger->debug(__METHOD__); - $logger->debug("PASSING HERE!"); return $this->config->isEnabled() ? 'media_gallery/index/index' : $result; } } From 0192ca576be48357640029f10edf35e829f2318b Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Wed, 12 Aug 2020 22:13:59 +0800 Subject: [PATCH 3/4] magento/adobe-stock-integration#1712: Remove DataObject usage from OpenDialogUrl provider - fixed static test fails and removed unused class --- .../Model/OpenDialogUrlProvider.php | 40 ------------------- .../Plugin/NewMediaGalleryOpenDialogUrl.php | 5 +++ .../MediaGalleryIntegration/composer.json | 3 +- 3 files changed, 7 insertions(+), 41 deletions(-) delete mode 100644 app/code/Magento/MediaGalleryIntegration/Model/OpenDialogUrlProvider.php diff --git a/app/code/Magento/MediaGalleryIntegration/Model/OpenDialogUrlProvider.php b/app/code/Magento/MediaGalleryIntegration/Model/OpenDialogUrlProvider.php deleted file mode 100644 index 317b811df5692..0000000000000 --- a/app/code/Magento/MediaGalleryIntegration/Model/OpenDialogUrlProvider.php +++ /dev/null @@ -1,40 +0,0 @@ -config = $config; - } - - /** - * Get Url based on media gallery configuration - * - * @return string - */ - public function getUrl(): string - { - return $this->config->isEnabled() ? 'media_gallery/index/index' : 'cms/wysiwyg_images/index'; - } -} diff --git a/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php b/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php index 13068721634e8..ed8108f012af0 100644 --- a/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php +++ b/app/code/Magento/MediaGalleryIntegration/Plugin/NewMediaGalleryOpenDialogUrl.php @@ -10,6 +10,9 @@ use Magento\MediaGalleryUiApi\Api\ConfigInterface; use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl; +/** + * Plugin to get open media gallery dialog URL for WYSIWYG and widgets + */ class NewMediaGalleryOpenDialogUrl { /** @@ -26,6 +29,8 @@ public function __construct(ConfigInterface $config) } /** + * Get Url based on media gallery configuration + * * @param OpenDialogUrl $subject * @param string $result * @SuppressWarnings(PHPMD.UnusedFormalParameter) diff --git a/app/code/Magento/MediaGalleryIntegration/composer.json b/app/code/Magento/MediaGalleryIntegration/composer.json index c55d6e0b89733..a9709da81222e 100644 --- a/app/code/Magento/MediaGalleryIntegration/composer.json +++ b/app/code/Magento/MediaGalleryIntegration/composer.json @@ -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": "*" From e2f28054c87bba6cc8457c1f910ad808e32622e5 Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Thu, 13 Aug 2020 21:29:48 +0800 Subject: [PATCH 4/4] magento/adobe-stock-integration#1712: Remove DataObject usage from OpenDialogUrl provider - apply requested changes --- .../Form/Element/DataType/Media/OpenDialogUrl.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php b/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php index cd116a6f1bff8..9961fc41fc70d 100644 --- a/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php +++ b/app/code/Magento/Ui/Component/Form/Element/DataType/Media/OpenDialogUrl.php @@ -20,6 +20,14 @@ class OpenDialogUrl */ private $openDialogUrl; + /** + * @param string $url + */ + public function __construct(string $url = null) + { + $this->openDialogUrl = $url ?? self::DEFAULT_OPEN_DIALOG_URL; + } + /** * Returns open dialog url for media browser * @@ -27,9 +35,6 @@ class OpenDialogUrl */ public function get(): string { - if ($this->openDialogUrl) { - return $this->openDialogUrl; - } - return self::DEFAULT_OPEN_DIALOG_URL; + return $this->openDialogUrl; } }